search

Home  >  Q&A  >  body text

nginx reverse proxy static resource 403 error?

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

为情所困为情所困2735 days ago926

reply all(2)I'll reply

  • 巴扎黑

    巴扎黑2017-06-28 09:24:47

    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

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-06-28 09:24:47

    The reason is that the alias command was used incorrectly.
    Official Documents

    If alias is used inside a location defined with a regular expression
    then such regular expression should contain captures and alias should
    refer to these captures (0.7.40)
    http://nginx.org/r/alias

    Try the following configuration

            location ~ .*\.(css|js|jpg|png|gif)$ {
                    alias "/root/nodeApp/public/";
                    expires 3d;
            }

    reply
    0
  • Cancelreply