首页 > 解决方案 > 无法在 Nginx 中配置子域

问题描述

经过 4 个小时的奋斗和互联网挖掘,我似乎无法理解为什么这个 Nginx 配置不起作用。

目标: 我有两个完全不同的项目,我想使用子域将它们托管在同一个域上。所以项目一将是one.example.com,而项目二必须是two.example.com。我还在端口上设置了两个不同的节点 js 服务器40004001并且希望将项目一路由到4000并将项目二路由到4001.

server {
    listen 80;
    server_name one.example.com;

    location / {
        proxy_pass http://127.0.0.1:4000/;
    }
}

server {
    listen 80;
    server_name two.example.com;

    location / {
        proxy_pass http://127.0.0.1:4001/;
    }
}

使用的命令service nginx start

我得到的错误 Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.

标签: nginxproxysubdomain

解决方案


为了解决我的问题,我必须/etc/nginx/nginx.conf将这一行添加到 http server 块的顶部:server_names_hash_bucket_size 64;


推荐阅读