参考网站使用Nginx和SSL在Ubuntu上正确使用端口8080

时间:2018-04-27 06:48:21

标签: ssl nginx .net-core ssl-certificate certbot

大家好日子,

我正在尝试在ubuntu 16.04上发布我的示例ASP.NET Core应用程序,代理服务器是Nginx。

我的服务器拥有LetsEncript提供的SSL证书。一切正常。但是,当我尝试使用与示例端口8080一起提供的Web应用程序时,它不起作用并且nginx页面仍然显示,即使我已经在默认文件中注释掉它。

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


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


    listen 80 default_server;
    listen [::]:80 default_server;

  location / {
        proxy_pass http://localhost:8080;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection keep-alive;
        proxy_set_header Host $http_host;
        proxy_cache_bypass $http_upgrade;
   }

    server_name mywebsite.com www.mywebsite.com;
    return 404; # managed by Certbot
}

Full default file

(由于隐私,我需要不透露确切的域名)

顺便说一句,我的真实域名正常工作,localhost:8080在服务器内正常运行。

1 个答案:

答案 0 :(得分:0)

您必须在服务器{}内声明位置,内部为443。

location / {
    proxy_pass http://localhost:8080;
        proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection keep-alive;
    proxy_set_header Host $http_host;
    proxy_cache_bypass $http_upgrade;
}

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

保存默认文件,然后重新启动nginx

sudo systemctl restart nginx