I have a web application which is accessed through nginx, which acts as a reverse proxy. However, a subpath of this application is aliased to a directory. The server configuration is as follows:
server {
# ...
location /myapp/files {
alias /var/www/myapp/files;
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/htpasswd;
}
location /myapp/ {
proxy_pass http://127.0.0.1:3000/;
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/htpasswd;
}
}
The above setup aliases all requests to /myapp/files
regardless of the request method. Is there a way to alias only GET requests to /myapp/files
, and proxy the DELETE method to the web application?
Limitations of if prevent something like this being written:
if ($request_method = "GET") {
location /myapp/files {
alias /var/www/myapp/files;
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/htpasswd;
}
}
As suggested in the comments, trying to do something like this with my configuration:
location /myapp/files {
auth_basic Restricted;
auth_basic_user_file /etc/nginx/htpasswd;
if ($request_method = "GET") {
alias /var/www/myapp/files;
}
if ($request_method = "DELETE") {
proxy_pass http://127.0.0.1:3000/;
}
}
}
results in:
nginx: [emerg] "alias" directive is not allowed here in /etc/nginx/sites-enabled/default:44
How can I achieve this?