NGINX https://www.example.com不起作用Certbot,ASP Net Core

时间:2019-02-27 13:05:36

标签: nginx asp.net-core certbot

请帮助,我无法在Nginx(ubuntu)上建立网站。

我的站点是ASP Net Core站点(这就是我转发标题的原因) 我正在尝试将以下所有选项重定向到同一网站和

仅通过安全层(HTTPS)进行通信

当前,除选项4之外,所有其他功能均正常工作

  1. http://example.com
  2. https://example.com
  3. http://www.example.com
  4. https://www.example.com

如果有人可以举一个如何整齐地维护多个站点的配置的示例,那我对Nginx和路由一般来说还是很陌生的。

我当前的配置(运行nginx -T之后)

# configuration file /etc/nginx/sites-enabled/default:
server {
 listen 80; 
 location / {
 proxy_pass http://localhost:5000;
 proxy_http_version 1.1;
 proxy_set_header Upgrade $http_upgrade;
 proxy_set_header Connection keep-alive;
 proxy_set_header Host $host;
 proxy_cache_bypass $http_upgrade;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 proxy_set_header X-Forwarded-Proto $scheme;
 }
}    
configuration file /etc/nginx/sites-enabled/example.com:

    server {

            root /var/www/example.com;

            server_name example.com www.example.com;

            location / {
                    proxy_pass         http://localhost:5000;
                    proxy_http_version 1.1;
                    proxy_set_header   Upgrade $http_upgrade;
                    proxy_set_header   Connection keep-alive;
                    proxy_set_header   Host $host;
                    proxy_cache_bypass $http_upgrade;
                    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

            proxy_set_header   X-Forwarded-Proto $scheme;
            }

        listen [::]:443 ssl ipv6only=on; # managed by Certbot
        listen 443 ssl; # managed by Certbot
        ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/example.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





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


        if ($host = www.example.com) {
            return 301 https://$host$request_uri;
        } # managed by Certbot


            listen 80;
            listen [::]:80;

            server_name example.com www.example.com;
        return 404; # managed by Certbot




    }

0 个答案:

没有答案