nginx:两个域->两个应用->一台服务器

时间:2018-09-02 19:39:17

标签: nginx supervisord

这应该很简单,但是我整天都在努力地设置它。这是我的conf文件:

# Expires map
  map $sent_http_content_type $expires {
    default                    off;
    text/html                  epoch;
    text/css                   max;
    application/javascript     max;
    ~image/                    max;
}


server {
    listen  80;
    server_name www.firstdomain.com firstdomain.com;
    root /path/to/project/;
    error_log /var/log/nginx/error.log;

}

server {
    listen 443 ssl http2; # managed by Certbot
    server_name www.firstdomain.com;
    error_log /var/log/nginx/error.log;

    proxy_read_timeout  90;
    expires $expires;

    location / {
        include proxy_params;
        proxy_read_timeout  90;
        proxy_pass http://xx.xxx.xxx.xxx:8001;

    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        alias /path/to/static/;
    }

    location /media/ {                        
        alias /path/to/media/;
    }

    location  /robots.txt {
        alias  /path/to/robots.txt;
    }

    ssl_certificate /etc/letsencrypt/live/firstdomain.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/firstdomain.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

    if ($host = 'firstdomain.com') {
        return 301 https://www.firstdomain.com$request_uri;
    }

    if ($scheme != "https") {
        return 301 https://www.firstdomain.com$request_uri;
    } # managed by Certbot
}

这是我的第二个域,存储在站点中的单独文件中:

server {
    listen 80;
    server_name www.second-domain.com second-domain.com;
    error_log my-domain-path/nginx.log;

    location /
    {
        proxy_pass http://www.second-domain.com:8002;
    }
}

两个应用程序均由主管管理,并且都成功启动。但是,当我导航到www.second-domain.com时,我得到的是firstdomain.com的内容。

我确定第二个域的内容可以正常运行,因为如果我导航到IP:PORT位置就可以看到它,但是该域名不起作用。

为什么?

0 个答案:

没有答案