简体   繁体   English

使用NGINX在一个VPS实例中的多个网站

[英]Multiple websites in one VPS instance with NGINX

I still struggling with configuration of nginx for multiple websites in one virtual machine. 我仍然在为一台虚拟机中的多个网站配置nginx而苦苦挣扎。 So If I do: 因此,如果我这样做:

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;
    }
}

after hit example1.com my nodejs page is loaded properly. 点击example1.com之后,我的nodejs页面已正确加载。 But If I try to add second server block: 但是,如果我尝试添加第二个服务器块:

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;
    }
}

Nothing is working, also example1. 什么也没有用,同样是example1。 So I wanna to load through example2.com default nginx location... Something like that: 因此,我想通过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;
    }
}

But it is always redirected to nginx root location. 但是它总是重定向到nginx根目录。

How can I do that? 我怎样才能做到这一点? Thanks for any help! 谢谢你的帮助!

Node.JS? Node.js的?

You can refer my configuration: 您可以参考我的配置:

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;
}

or another one 或另一个

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;
}

The first configuration direct to https redirect cycle. 第一个配置直接指向https重定向周期。

And you said the default site, you can config something like that: 您说默认站点,您可以配置如下内容:

listen 80 default;
server_name xxxxx.com;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM