目前我正在使用nginx来提供我的API文档(mywebsites.com)的静态文件,我想添加另一个网站:mywebsites.com/ website。
因此,我编辑了nginx配置文件以同时为它们提供服务:
server {
listen 0.0.0.0:80;
server_name mywebsite.com;
client_max_body_size 1m;
access_log /var/log/nginx/error.log;
error_log /var/log/nginx/static.log;
#location ~ /\.git {
# deny all;
#}
location /subwebsite {
root /home/api/portal/build;
index index.html index.htm;
try_files $uri $uri/ =404;
}
location / {
root /home/api/application/public;
index index.html index.htm;
try_files $uri $uri/ =404;
}
#sendfile off;
}
问题是当我尝试访问新网站时:mywebsite.com/subsite..我找不到404。
当我尝试更改当前服务器以转发到新的子网站时(而不是添加location /subwebsite,我更改了location /的根目录)。
原始文件:
server {
listen 0.0.0.0:80;
server_name mywebsite.com;
client_max_body_size 1m;
access_log /var/log/nginx/error.log;
error_log /var/log/nginx/static.log;
location ~ /\.git {
deny all;
}
location ~ {
root /home/api/application/public;
index index.html index.htm;
try_files $uri $uri/ =404;
}
sendfile off;
}
我错过了什么?提前感谢
发布于 2019-05-08 20:55:53
我认为,这个变种的位置,可以为你工作:
location /subwebsite {
root /home/api/portal/build;
try_files $uri /index.html;
}
这样的配置文件似乎更具可读性:
server {
listen 0.0.0.0:80;
server_name mywebsite.com;
root /home/api/application/public;
index index.html index.htm;
client_max_body_size 1m;
access_log /var/log/nginx/error.log;
error_log /var/log/nginx/static.log;
#location ~ /\.git {
# deny all;
#}
location /subwebsite {
root /home/api/portal/build;
try_files $uri /index.html;
}
#sendfile off;
}
https://stackoverflow.com/questions/56023671
复制相似问题