使用Nginx配置子域

时间:2019-07-14 04:51:12

标签: nginx server digital-ocean

在此之前,我需要说我从未设置过服务器。也就是说,我正在尝试在数字海洋上设置Nginx服务器。我已经建立并运行了主站点,但是我正在尝试设置一个子域。我真的不知道我在做什么,但是我正在使用ssl证书,但是似乎无法显示子域。我收到浏览器错误Page isn't working too many redirects in the browser。我运行了该命令以测试ngninx语法,并通过了该命令。我以为我所要做的就是添加一个服务器块,其根目录指向文件夹,但是我想我可能是错的,或者我在途中做错了什么。主站点是一个节点应用程序,运行良好,但是现在我只是试图在子域中提供一个静态html文件。我重新启动了nginx,然后尝试重新启动,但是没有运气。这是我的/ etc / nginx / sites-enabled / default文件:

server {
    if ($host = example.com) {
        return 301 https://$host$request_uri;
    } 

    if ($host = dev.example.com) {
        return 301 https://$host$request_uri;
    } 

    listen 80;
    listen [::]:80  ;
    server_name example.com, dev.example.com;
    return 404;

}

server {
    # Enable HTTP/2
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name example.com;

    # Use the Let’s Encrypt certificates
    ssl_certificate /etc/letsencrypt/live/example.com-0001/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com-0001/privkey.pem;

    # Include the SSL configuration from cipherli.st
    include snippets/ssl-params.conf;

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-NginX-Proxy true;
        proxy_pass http://localhost:5000/;
        proxy_ssl_session_reuse off;
        proxy_set_header Host $http_host;
        proxy_cache_bypass $http_upgrade;
        proxy_redirect off;
    }


}

server {
    return 301 https://$host$request_uri;

    server_name dev.example.com;

    listen [::]:443 ssl;
    listen 443 ssl;

    # Use the Let’s Encrypt certificates
    ssl_certificate /etc/letsencrypt/live/example.com-0001/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com-0001/privkey.pem;

    # Include the SSL configuration from cipherli.st
    include snippets/ssl-params.conf;

    root /home/username/apps/dev;
    index index.html index.htm;
}

任何帮助将不胜感激。

0 个答案:

没有答案
相关问题