本文以Lnmp的nginx 1.22为例
打开nginx.conf,以下是访问http自动跳转到https,301跳转
server {
listen 80;
server_name blog.70ci.com; #需要将yourdomain替换成证书绑定的域名。
rewrite ^(.*)$ https://$host$1 permanent; #将所有HTTP请求通过rewrite指令重定向到HTTPS。
location / {
index index.html index.htm;
}
}
server
{
listen 443 ssl;
#listen [::]:80;
server_name blog.70ci.com ;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/blog;
ssl_certificate /usr/local/nginx/conf/bak/blog.70ci.com.pem;
ssl_certificate_key /usr/local/nginx/conf/bak/blog.70ci.com.key;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 5m;
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers off;
include rewrite/wordpress.conf;
#error_page 404 /404.html;
# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
include enable-php-pathinfo.conf;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\.
{
deny all;
}
access_log /home/wwwlogs/blog.log;
}