node.js - 403 禁止 + Nginx + 虚拟主机配置 + NodeJS
问题描述
我在使用 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;
}
我已经根据这篇文章设置了所有配置。
需要帮助解决 403。在此先感谢。
编辑:
错误日志说:
“/mnt/var/www/example.com/app/public/”的目录索引被禁止。
解决方案
我认为您对虚拟主机的配置错误。这是我的 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
}
推荐阅读
- c# - 将 C# 代码拆分为 2 种方法以更可靠
- azure-storage - 扩展 Azure 存储 GUI
- node.js - Braintree“订阅”和“附加组件”
- perl - 如何在 Perl 中将总线一元化和/减少一点?
- python - 如何在python Tkinter程序中将变量参数传递给MYSQL数据库查询
- java - Springboot 应用程序已启动,但 POST 请求始终返回“未找到”
- bash - find 列出的文件列表的 md5sum
- angular - 如何在 *ngfor 项目中单击按钮时显示单独的事件?
- jenkins - 如何在管道的下游作业中获取上游作业已运行的节点名称
- ios - 了解 Apple 远程收据