[英]Nodejs Nginx serve static files
我有在端口5000上运行的nodejs。还有另一个在主端口8000上运行的应用程序。
第一个是php app,这是主要的。 和nodeApp作为第二个应用程序。
因此,这是我的Nginx网站可用/默认文件:
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/analytics_dashboard/public;
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location /nodeApp/ {
root /root/nodeApp/source/front/dist/static;
rewrite ^/nodeApp/(.*) /$1 break;
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /static {
root /root/nodeApp/source/front/dist/static;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
}
location ~ /\.ht {
deny all;
}
因此,当我进入/主页时,我可以访问php应用程序。
当我来到/ nodeApp /时,我看到了nodeApp的html页面。 但是有403错误。
像这样的http://<my-server>/static/js/...
403禁止的错误。
这是nginx错误日志:
"GET /static/js/app.b790250b5af64ad68f13.js HTTP/1.1" 403 192 "http://<my-server>/marser/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36"
这是我在nginx错误日志中的内容:
/root/nodeApp/source/front/dist/static/js/app.b790250b5af64ad68f13.js" failed (13: Permission denied), request: "GET /static/js/app.b790250b5af64ad68f13.js HTTP/1.1"
但是,我为chmod 777
设置了静态目录中所有文件的权限。
我也尝试过重写nginx网站-可用/默认文件来更改
location /static {
alias /root/nodeApp/source/front/dist/static;
}
但是仍然没有成功。
所以,我的问题是:
如何在Nginx中为第二个应用程序提供Node.js应用程序静态文件?
作为实验,您可以尝试打开自动索引,然后查看错误消息是否更改。 如果由于某种原因您的请求正在查找目录而不是文件,则在禁用自动索引的情况下会看到403错误。 在服务器节顶部附近添加以下内容:
autoindex on;
如果nginx配置了--with-debug
(要检查nginx -V),请尝试通过在错误日志末尾添加“ debug”来启用调试模式:
error_log /var/log/nginx/example.com.error.log debug;
这将跟踪nginx如何处理请求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.