Nginx Location Configuration for Nested Subfolders
In the context of Nginx configuration, accessing subfolders with specific URIs can be challenging. This is where location directives come into play.
Consider the following scenario: you have a directory structure like /var/www/mysite/ containing two subfolders, /static and /manage. You wish to access /static via the root URI (e.g., "http://example.org/") and /manage via "/manage" (e.g., "http://example.org/manage").
Let's break down the provided Nginx configuration:
server { listen 80; server_name example.org; ... # Static folder location location / { root $uri/static/; index index.html; } # Manage folder location (attempt 1) location /manage { root $uri/manage/public; try_files $uri /index.php$is_args$args; } # PHP processing location location ~ \.php { ... } }
While the / location works correctly, the /manage location fails. This is because the root directive is incorrect. To use a subfolder within an alias, alias should be used instead of root.
The updated location for /manage should be as follows:
location ^~ /manage { alias /var/www/mysite/manage/public; ... }
With these modifications, Nginx will correctly serve the static files from /static at the root URI and the dynamic content from /manage at "/manage".
The above is the detailed content of How Can I Configure Nginx to Serve Nested Subfolders from Different URIs?. For more information, please follow other related articles on the PHP Chinese website!