Reputation: 95
My nginx vhost config content:
server {
listen 80;
server_name t.xianzhi.xxx.domain;
access_log /data/log/nginx/t.xianzhi.xxx.domain_access.log main;
location ~ /\. {deny all;}
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
location = / {
root /data/web/static/html;
index index.html;
}
location / {
proxy_pass http://127.0.0.1:9000;
}
location = /favicon.ico {
access_log off;
root /data/web/static/;
}
location = /apple-app-site-association {
add_header Content-Type "text/html; charset=utf-8";
root /data/web/show/public/wap/;
}
location ~ \.(css|js|png|jpg|woff|ttf)$ {
root /data/web/static;
expires 10d;
}
}
As the config, I want to server the path /
to /data/web/static/html/index.html
and server the others to proxy_pass.
The truth is the path /
is 404 not found and the others is successful.
The log is :
24/Aug/2017:10:49:43 +0800 10.5.17.37 t.xianzhi.xxx.domain - curl/7.51.0 - request:GET / HTTP/1.1 bbs:233status:404 upad:127.0.0.1:9000 rspt:0.017 rqtt:0.017 request_body:-
So, the /
is passed to proxy.
Some info:
The nginx version: nginx/1.10.1
So, how to fix it?
Upvotes: 2
Views: 285
Reputation: 146510
The problem is your = /
location block. If you consider the section
location = / {
root /data/web/static/html;
index index.html;
}
You specify the root and index.html, but you don't server anything. So you should change it to
location = / {
root /data/web/static/html;
index index.html;
try_files /index.html =404;
}
or
location = / {
root /data/web/static/html;
try_files /index.html =404;
}
Upvotes: 1