【问题标题】:Multiple websites in one VPS instance with NGINX一个使用 NGINX 的 VPS 实例中的多个网站
【发布时间】:2015-10-15 13:06:44
【问题描述】:

我仍在为一台虚拟机中的多个网站配置 nginx 而苦苦挣扎。 所以如果我这样做:

server {
    listen 80;

    server_name example1.com;

    location / {
        proxy_pass http://localhost:8181;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

点击 example1.com 后,我的 nodejs 页面已正确加载。但是如果我尝试添加第二个服务器块:

server {
    listen 80;

    server_name example2.com;

    location / {
        proxy_pass http://localhost:8080;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

没有任何效果,example1也是如此。所以我想通过 example2.com 默认 nginx 位置加载...类似的东西:

server {
    listen 80;

    server_name example1.com;

    location / {
          root /usr/share/nginx/html;
          index index.html index.htm;
    }
}

server {
    listen 80;

    server_name example2.com;

    location / {
        proxy_pass http://localhost:8181;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

但它总是被重定向到 nginx 根位置。

我该怎么做?感谢您的帮助!

【问题讨论】:

    标签: node.js nginx reverse-proxy


    【解决方案1】:

    Node.JS?

    你可以参考我的配置:

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_pass http://127.0.0.1:2368;
    }
    

    或者另一个

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;
        proxy_pass http://127.0.0.1:2387;
    }
    

    第一个配置直接到https重定向循环。

    你说的是默认站点,你可以这样配置:

    listen 80 default;
    server_name xxxxx.com;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多