【问题标题】:Nginx Multiple Domains One App and ServerNginx 多域一个应用和服务器
【发布时间】:2014-02-25 05:33:43
【问题描述】:

我想在同一个 django 应用和同一个 nginx 服务器上运行多个网站。 我成功运行 http://myip/ 和 http://myip/name1 和 http://myid/name2

现在我想将所有这些项目链接到 myname.com 和 name1.com 和 name2.com

我应该如何更改我的 nginx 配置文件?该文件的当前版本如下所示。谢谢

upstream crsq {
      server localhost:8000;
}

server {

    listen 80 default;

    access_log /home/ubuntu/crsq-access.log;
    error_log /home/ubuntu/crsq-error.log error;

    # Make site accessible from http://localhost/
    server_name crsq;

    location @proxy_to_crsq_app {
        proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
        proxy_set_header X-Forwarded-Port $http_x_forwarded_port;
        proxy_set_header X-Forwarded-For $http_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http: //crsq;
    }

    location /robots.txt {
        alias /home/ubuntu/crsq/crsq/robots.txt;
    }


    location / {
        try_files $uri @proxy_to_crsq_app;
    }

    location /static {
        alias /home/ubuntu/crsq/crsq/static;
    }
}

【问题讨论】:

    标签: django nginx webserver


    【解决方案1】:
    upstream crsq {
          server localhost:8000;
    }
    
    server {
    
        listen 80 ;
    
        access_log /home/ubuntu/crsq-access.log;
        error_log /home/ubuntu/crsq-error.log error;
    
        # Make site accessible from http://localhost/
        server_name a.b.c;
    
        location @proxy_to_crsq_app {
            proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
            proxy_set_header X-Forwarded-Port $http_x_forwarded_port;
            proxy_set_header X-Forwarded-For $http_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_redirect off;
            proxy_pass http: //crsq;
        }
    
        location /robots.txt {
            alias /home/ubuntu/crsq/crsq/robots.txt;
        }
    
    
        location / {
            try_files $uri @proxy_to_crsq_app;
        }
    
        location /static {
            alias /home/ubuntu/crsq/crsq/static;
        }
    }
    server {
    
        listen 80 ;
    
        access_log /home/ubuntu/crsq-access.log;
        error_log /home/ubuntu/crsq-error.log error;
    
        # Make site accessible from http://localhost/
        server_name b.c.d;
    
        location @proxy_to_crsq_app {
            proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
            proxy_set_header X-Forwarded-Port $http_x_forwarded_port;
            proxy_set_header X-Forwarded-For $http_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_redirect off;
            proxy_pass http: //crsq;
        }
    
        location /robots.txt {
            alias /home/ubuntu/crsq/crsq/robots.txt;
        }
    
    
        location / {
            try_files $uri @proxy_to_crsq_app;
        }
    
        location /static {
            alias /home/ubuntu/crsq/crsq/static;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-13
      • 2018-02-10
      • 2023-03-25
      • 2022-11-23
      • 2019-10-29
      • 1970-01-01
      • 2019-06-30
      • 1970-01-01
      相关资源
      最近更新 更多