这是我的/etc/sites-available/default
server {
listen 443 default_server;
server_name _;
ssl on;
ssl_certificate /etc/ssl/certs/example/example.com.crt;
ssl_certificate_key /etc/ssl/certs/example/example.com.key;
root /usr/share/nginx/html;
index index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
}
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
return 301 https://$host$request_uri;
root /usr/share/nginx/html;
index index.html index.htm;
# Make site accessible from http://localhost/
server_name localhost;
location / {
try_files $uri $uri/ =404;
}
}
第一块是我最近添加的。我在这台服务器上托管了多个子域。这是sites-available/my.example.com
:
server {
server_name my.example.com;
access_log /var/data/log/nginx/my.example.com.log;
error_log /var/data/log/nginx/my.example.com.log;
root /var/data/www/lmy.example.com/htdocs;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
}
每当我去http://my.example.com
时,网站都会正常加载。但现在,转到https://my.example.com
只会转到默认页面。 my.example.com
文件是sites-enabled
的符号链接。配置似乎很好,因为如果我对return 301 ...
块中的行port 80
发表评论,http://my.example.com
会再次生效,但https://my.example.com
会显示默认的nginx页面。