reactjs - 配置nginx服务两个网站
问题描述
目前我正在使用 nginx 来提供我的 API 文档(mywebsites.com)的静态文件,我想添加另一个网站:mywebsites.com/subwebsite。
所以我编辑了 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/subwebsite .. 找不到 404。
当我尝试更改当前服务器以转发到新的子网站时(而不是添加位置 / 子网站,我更改了位置 / 的根目录)它可以工作。
原始文件:
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;
}
我在这里缺少什么?提前致谢
解决方案
我认为,这种位置变体可能对您有用:
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;
}
推荐阅读
- mfc - 使用 TVITEMEX 代替 TVITEM 结构有什么好处?
- varnish - 无法开始使用 Varnish 和 Wordpress - 教程已过时?
- html - 对超链接使用“border-bottom”而不是“text-decoration”——它在语义上是否正确?
- php - 不能不安装任何包 throw pecl?
- javascript - 向未公开的收件人发送电子邮件 nodemailer
- python - Django 遍历关系
- mpi - 如何通过 SLURM 向正在运行的 MPI 作业添加更多进程和节点?
- logic - CFC和梯形图程序可以在单个codesys项目中运行吗
- php - REST API JWT 身份验证标头在 Bitnami Wordpress 实例中不起作用
- javascript - 如何在jQuery中动画后删除元素?