Deploy the Node project for online testing. When using nginx reverse proxy, a static resource 403 error occurs. The local configuration is correct, but the same configuration online produces an error. The configuration is as follows:
upstream nodeblog{
server 127.0.0.1:3000;
keepalive 65;
}
server {
listen 443;
ssl on;
server_name ;
ssl_certificate ;
ssl_certificate_key ;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ;
ssl_session_timeout 5m;
ssl_prefer_server_ciphers on;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Nginx-Proxy true;
proxy_set_header Connection '';
proxy_pass http://nodeblog;
}
location ~ .*\.(css|js|jpg|png|gif)$ {
alias "/root/nodeApp/public/";
expires 3d;
}
}
Following the prompts, I set 777 permissions for all files in the directory, but still got a 403 error
I found a reason. Because it is operated under root permissions, it may be that nginx does not have permissions to the directory. Therefore, the personal server has not assigned other users, so open the first line of nginx.conf and change user nobody to user root so that nginx can Run with root privileges.
This is definitely not a good solution. I have a general understanding of the reason for 403. The nginx process does not have relevant permissions for the current static resource folder. You need to separately set nginx’s permissions for this directory.
Hope there is a good solution
The reason is that the
alias
command was used incorrectly.Official Documents
Try the following configuration