Nginx的Httpsredirect不工作在Ubuntu 16.04

如何将所有HTTP请求redirect到Nginx中的HTTPS? 我已经按照下面的链接:

https://www.thecodeship.com/web-development/guide-implementing-free-ssl-certificate-nginx-lets-encrypt/

以下是我已经添加到我的网站的configuration文件的代码。

server { listen 80; listen [::]:80; server_name mydomain.com; include /etc/nginx/snippets/letsencrypt.conf; location / { return 301 https://mydomain$request_uri; } } server { server_name mydomain.com; listen 443 ssl http2; listen [::]:443 ssl http2; ssl_certificate /etc/letsencrypt/live/mydomain.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/mydomain.com/privkey.pem; ssl_trusted_certificate /etc/letsencrypt/live/mydomain.com/fullchain.pem; include /etc/nginx/snippets/ssl.conf; root /var/www/mydomain.com/public_html/public; index index.html 1.html; location / { try_files $uri $uri/ =404; } } 

我在每个http和https中获得不同的页面。 任何人都可以告诉我什么应该改变在configuration的服务器块redirect到https?

http根指的是

 root /var/www/mydomain.com/public_html; index index.html sample.html; 

https根指的是

 root /var/www/mydomain.com/public_html/public; index index.html 1.html; 

提前致谢。