Nginx多个域一个应用程序和服务器

时间:2014-02-25 05:33:44

标签: django nginx webserver

我想在同一个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;
    }
}

1 个答案:

答案 0 :(得分: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;
    }
}