首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >配置nginx服务两个网站

配置nginx服务两个网站
EN

Stack Overflow用户
提问于 2019-05-07 21:24:09
回答 1查看 47关注 0票数 0

目前我正在使用nginx来提供我的API文档(mywebsites.com)的静态文件,我想添加另一个网站:mywebsites.com/ website。

因此,我编辑了nginx配置文件以同时为它们提供服务:

代码语言:javascript
运行
复制
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 /的根目录)。

原始文件:

代码语言:javascript
运行
复制
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;
}

我错过了什么?提前感谢

EN

回答 1

Stack Overflow用户

发布于 2019-05-08 20:55:53

我认为,这个变种的位置,可以为你工作:

代码语言:javascript
运行
复制
location /subwebsite {
    root  /home/api/portal/build;
    try_files $uri /index.html;
}

这样的配置文件似乎更具可读性:

代码语言:javascript
运行
复制
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;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56023671

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档