我已经设置了一个Nginx服务器,如果没有找到html文件,它会向节点服务器执行proxy_pass。我可以正常访问我的静态html文件但是当我点击Node服务器时,我得到了403:Forbidden。如果有帮助,这是我的Nginx conf:
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=one:8m max_size=3000m inactive=600m;
upstream mysite_upstream {
server 127.0.0.1:8000;
keepalive 64;
}
server {
listen 80;
server_name staging.mysite.org;
root /var/www/staging.mysite.org/public;
access_log /var/logs/staging.mysite.org.access.log;
error_log /var/logs/staging.mysite.org.error.log;
error_page 404 /404.html;
error_page 500 503 /500.html;
location ~ ^/(images/|javascript/|js/|css/|style/|flash/|robots.txt|sitemap.xml|humans.txt|favicon.ico) {
access_log off;
expires max;
}
location @node {
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Connection "";
proxy_http_version 1.1;
proxy_cache one;
proxy_cache_key sfs$request_uri$scheme;
proxy_pass http://mysite_upstream;
}
location / {
try_files $uri $uri/ $uri.html @node;
}
}
我应该提一下,如果我直接从try_files
取出proxy_pass
而只是/
,则会提供Node应用,但我会获得所有静态html文件的404。此外,这在我的本地机器(osx)上工作正常。