使用Nginx在ubuntu上托管多个子域

时间:2019-07-12 19:58:39

标签: nginx nginx-config

我在ubuntu ec2服务器中使用nginx托管主域和子域文件。我的子域是一个有角度的应用程序,而主域只是一个简单的静态页面。

我面临的问题是,导航到domain.com主站点时,它将重定向到子域网站。

要配置nginx以同时服务于两个域,我创建了两个名称为 edcerts.io和demo.edcerts.io

我的edcerts.io块的内容如下

server {


    listen       443 ssl http2 ;
    listen       [::]:443 ssl http2;
    server_name  edcerts.io www.edcerts.io;
    root         /var/www/html/edcerts.io/index.html;
    access_log /var/log/nginx/access_log combined;

    ssl_certificate "/etc/letsencrypt/live/edcerts.io/fullchain.pem";
    ssl_certificate_key "/etc/letsencrypt/live/edcerts.io/privkey.pem";
    # It is *strongly* recommended to generate unique DH parameters
    # Generate them with: openssl dhparam -out /etc/pki/nginx/dhparams.pem 2048
    #ssl_dhparam "/etc/pki/nginx/dhparams.pem";
    ssl_session_cache shared:SSL:1m;
    ssl_session_timeout  10m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers HIGH:SEED:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!RSAPSK:!aDH:!aECDH:!EDH-DSS-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA:!SRP;
    ssl_prefer_server_ciphers on;

      location / {
        # First attempt to server request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ /index.html =404;
    }



}


server {
    listen 80;
    listen [::]:80;



    return 301 https://edcerts.io;
}



而子域阻止如下

server {


    listen       443 ssl http2 ;
    listen       [::]:443 ssl http2 ;
    server_name  demo.edcerts.io;
    root         /var/www/html/demo.edcerts.io/dist;

    access_log /var/log/nginx/access_log combined;

    ssl_certificate "/etc/letsencrypt/live/demo.edcerts.io/fullchain.pem";
    ssl_certificate_key "/etc/letsencrypt/live/demo.edcerts.io/privkey.pem";
    # It is *strongly* recommended to generate unique DH parameters
    # Generate them with: openssl dhparam -out /etc/pki/nginx/dhparams.pem 2048
    #ssl_dhparam "/etc/pki/nginx/dhparams.pem";
    ssl_session_cache shared:SSL:1m;
    ssl_session_timeout  10m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers HIGH:SEED:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!RSAPSK:!aDH:!aECDH:!EDH-DSS-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA:!SRP;
    ssl_prefer_server_ciphers on;

      location / {
        # First attempt to server request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ /index.html =404;
    }
    location /api/ {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;

    }



}


server {
    listen 80;
    listen [::]:80;

    return 301 https://demo.edcerts.io;
}



根据我的错误日志,当我点击demo.edcerts.io时,它显示GET请求,但是当我点击edcerts.io时,它不显示任何请求。

0 个答案:

没有答案