使用Nginx for NodeJS应用程序配置服务器虚拟主机时,我收到403 Forbidden。
配置文件代码:
server {
listen 443 default_server;
listen [::]:443 default_server;
ssl on;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
root /mnt/var/www/example.com/app/public/;
index index.html index.htm index.php;
server_name example.com www.example.com;
access_log /var/log/nginx/dygnostica_access.log;
error_log /var/log/nginx/dygnostica_error.log;
location / {
include /etc/nginx/proxy_params
try_files $uri $uri/ =404;
}
}
server {
listen 0.0.0.0:80;
server_name example.com www.example.com;
rewrite ^ https://$host$request_uri? permanent;
}
我已根据this文章设置了所有配置。
需要帮助解决403。在此先感谢。
编辑:
错误日志说:
禁止目录索引为“ /mnt/var/www/example.com/app/public /”。
答案 0 :(得分:0)
我认为您对虚拟主机的配置错误。这是我的nginx配置文件。我在主域上有标准PHP应用程序(https),在子域上有节点应用程序(在端口3000上运行):
#// virtual host for node app:
server {
server_name node.domain.cz;
location / {
proxy_pass http://127.0.0.1:3000;
}
}
#// host (for PHP app)
server {
listen 80;
server_name domain.cz www.domain.cz;
root /var/www/domain.cz/www;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
listen 443 ssl; # managed by Certbot
# ssl_certificate ...
if ($scheme != "https") {
return 301 https://$host$request_uri;
} # managed by Certbot
}