Opened 11 months ago

Last modified 11 months ago

#68621 assigned defect

Two nginx problems: 1. try_files will add "html" to the search path 2. 403 even though all permissions are set properly.

Reported by: qiulang Owned by: Schamschula (Marius Schamschula)
Priority: Normal Milestone:
Component: ports Version:
Keywords: Cc:
Port: nginx

Description

I have encountered 2 nginx problems that I feel they are bugs although I am not 100% sure.

Using the following nginx.conf to illustrate my problems. I host two web apps in one domain but on different paths, one url uses "/" and the other url uses "/za". But both web apps set their static files' base path to "/", not with a prefix, so I use a try_files in the 1st location rule to let nginx search the 2nd location for the webapp za related stuff.

From the error.log I found that nginx will search the path from /opt/local/html so to make my try_files statement work I have to write /../za$uri to skip the html path.

But the problem is when I use nginx -V to check the prefix it is /opt/local not /opt/local/html and for the first location rule share/nginx/html/dist/, it can correctly search /opt/local/share/nginx/html/dist/ not /opt/local/html/share/nginx/html/dist/.

Besides, /opt/local/html does not exist so where does html part come from?

server {
        ...

        location / {
            root   share/nginx/html/dist/;
            #root   /Users/langqiu/myapp/dist;
            try_files $uri $uri/ /../za$uri; #b/c there is no html folder
        }
        
        location /za/ {
            alias   share/nginx/html/za/;
        }
}

My second problem is about file permission as show in in the rule #root /Users/langqiu/myapp/dist; I have run chomd 755 to /Users/langqiu/myapp/dist (even 777) to make that folder can be read but I still get 403 error.

Only if I copy the files into /opt/local/share/nginx/html/ folder I won't get 403.

Change History (6)

comment:1 Changed 11 months ago by jmroot (Joshua Root)

Keywords: nginx removed
Owner: set to Schamschula
Port: nginx added
Status: newassigned

comment:2 Changed 11 months ago by Schamschula (Marius Schamschula)

Indeed, nginx.conf hasn't been patched for macOS. Each user has different requirements, so there isn't one "fits all" solution. I heavily modify nginx.conf on my machines (forbidden files/directories, https, proxy, rewrites, etc.). That said, we could use root /Library/WebServer/Documents, the longtime location on macOS.

The line root share/nginx/html/dist/; doesn't start with a /, so it is relative to some other path.

The line #root /Users/langqiu/myapp/dist; starts with a #, which means that it is commented out.

comment:3 Changed 11 months ago by qiulang

I comment out #root /Users/langqiu/myapp/dist; because it does not work. That is my second question.

comment:4 Changed 11 months ago by qiulang

About my first question, let me reiterate it.

The default value of root is html, but I have changed it to share/nginx/html/dist/ since I use a relative path here, so it is absolute path is prefix + my relative. The prefix is /opt/local as nginx -V shows, so the absolute path is /opt/local/share/nginx/html/dist/, which is correct so far.

What troubles me is the try_files part. From the error.log I can see nginx use /opt/local/html, so I was asking where does the final part html come from ?

comment:5 Changed 11 months ago by Schamschula (Marius Schamschula)

I don't recommend putting your web root under /opt/local. If you ever choose to remove MacPorts, you'll inadvertently delete your website(s).

Without your entire nginx.conf file, it is hard to answer where /opt/local/html is coming from. You can omit anything that might be a security issue.

comment:6 Changed 11 months ago by qiulang

I feel you don't get my question.

But anyway for my nginx.conf, just the default one with the location blocks I show here.

Note: See TracTickets for help on using tickets.