我不知道如何redirect/ index.html 。 我已经通过了在serverfault上的线程,我想我已经尝试了每个build议,包括:
location / index index.html在server级别, location /内location /和静态内容中 node.js代理语句到location ~ /i而不是location / 显然,在我的configuration的其他地方有什么问题。 这是我的nginx.conf:
worker_processes 1; pid /home/logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; error_log /home/logs/error.log; access_log /home/logs/access.log combined; include sites-enabled/*; }
和我的服务器configuration位于启用网站
server { root /home/www/public; listen 80; server_name localhost; # proxy request to node location / { index index.html index.htm; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-NginX-Proxy true; proxy_pass http://127.0.0.1:3010; proxy_redirect off; break; } # static content location ~ \.(?:ico|jpe?g|jpeg|gif|css|png|js|swf|xml|woff|eot|svg|ttf|html)$ { access_log off; add_header Pragma public; add_header Cache-Control public; expires 30d; } gzip on; gzip_vary on; gzip_http_version 1.0; gzip_comp_level 2; gzip_proxied any; gzip_min_length 1000; gzip_disable "msie6"; gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; }
其他一切正常工作。 请求会正确代理到节点,并且正确地提供静态内容。 我只需要能够转发到/index.html请求。
基本上, root指令(位置块内)没有提及完整的path 。 另外,一个; 在index指令结束时丢失(可能是一个错字,nginx通常会捕获这些错别字)。
所以,你的服务器configuration位于启用网站将看起来像这样(经过上述两个变化)…
服务器{
root / home / www / public;
听80;
server_name localhost;
index index.html index.htm;
#代理请求到节点
位置@proxy {
proxy_set_header主机$ http_host;
proxy_set_header X-Real-IP $ remote_addr;
proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://127.0.0.1:3010;
proxy_redirectclosures;
打破;
}
位置 / {
try_files $ uri $ uri / @proxy;
}
#configuration的其余部分
#...
#...
}