我試圖讓nginx爲特定子目錄下的請求提供靜態文件,而所有其他請求都是反向代理的,但沒有運氣(獲得404s)。例如,我想要http://domain.com/project/static/index.html和http://domain.com/project/static/subdir/file2.html分別映射到/var/www/domain.com/htdocs/index.html和/var/www/domain.com/htdocs/subdir/file2.html。對於靜態文件和反向代理的Nginx映射
所有其他請求應該是反向代理的。例如,http://domain.com/project/thisWillBeProxied.html和http://domain.com/project/subdir/soWillThis.html
這是我主動nginx的輪廓
server {
listen 8080;
server_name domain.com;
access_log /var/www/domain.com/log/nginx.access.log;
error_log /var/www/domain.com/log/nginx_error.log debug;
location/{
proxy_pass http://reverse-proxy-host/;
}
location ^~ /project/static/ {
alias /var/www/domain.com/htdocs;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/nginx-default;
}
}