在 conf 文件中增加 rewrite ^(.*)$ https://$host$1 permanent;,示例如下:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/html/typecho;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html index.php;

    server_name _;

    # http 强制转成 https
    rewrite ^(.*)$ https://$host$1 permanent;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
    }

    # pass PHP scripts to FastCGI server
    #
    location ~ .*\.php(\/.*)*$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.3-fpm.sock;
    }

    if (!-e $request_filename) {
        rewrite ^(.*)$ /index.php$1 last;
    }
}

标签: none

添加新评论