【发布时间】:2017-05-15 10:42:02
【问题描述】:
我的服务器在 DO 中运行在 Ubuntu 16.04 中。 我的问题是,当我尝试在没有 www 的情况下运行时,我的网站无法加载。
我从这里开始学习教程。 https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-16-04
我的目标是
- 将所有非www重定向到https://example.com
- 将所有www重定向到https://www.example.com
nginx/sites-available/nginx_config
server {
listen 80;
server_name example.com http://example.com;
return 301 https://example.com$request_uri;
}
server {
listen 80;
server_name www.example.com http://www.example.com;
return 301 https://www.example.com$request_uri;
}
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
include snippets/ssl-example.com.conf;
include snippets/ssl-params.conf;
root /home/tim/site.folder;
index index.html index.htm index.nginx-debian.html;
server_name _;
location ~ /.well-known {
allow all;
}
location / {
try_files $uri $uri/ =404;
}
}
到目前为止我所尝试的:
删除 第一个和第二个服务器块中的 http。 (在第二个服务器块中相同)
server {
listen 80;
server_name example.com;
return 301 https://example.com$request_uri;
}
【问题讨论】: