lnmp环境下面配置https 出现下载index.php的解决方案

step1:第一步去阿里云申请ssl免费证书

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
step2:配置nginx

server
    {
        listen 443;
        server_name zig.exile.cc;
        index index.html index.htm index.php default.html default.htm default.php;
        root  /home/wwwroot/zig.exile.cc;
        ssl on;
		ssl_certificate   /usr/local/nginx/cert/2173934_zig.exile.cc.pem;
        ssl_certificate_key  /usr/local/nginx/cert/2173934_zig.exile.cc.key;
        ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
		


		
        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/zig.exile.cc.log;
	    }

此时这个配置文件访问https://zig.exile.cc 会出现下载文件的现象,网络上很多博客都说在nginx.conf文件中加入一段配置就好了,于是小编偷偷摸摸的加入如下配置文件:

location ~ .php?.*$ {
root /usr/local/nginx/html; # 设置网站根目录
fastcgi_pass 127.0.0.1:9000; # 此处是配置过程中最大的坑 稍后说明
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME d o c u m e n t r o o t / document_root/ documentroot/fastcgi_script_name;
include fastcgi_params;
}

结果更坑,php_fm 压根没有在9000端口监听,压上那一段配置,nginx直接抛出502异常,小编直接懵了,最后小编查看php-fpm.conf的监听文件,才发现根本不是那么回事
在这里插入图片描述
最后修改后的nginx配置文件

server
{
listen 80;
#listen [::]:80;
server_name zig.exile.cc;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/zig.exile.cc;

    include rewrite/thinkphp.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/zig.exile.cc.log;
}
   	server
{
    listen 443;
    server_name zig.exile.cc;
    index index.html index.htm index.php default.html default.htm default.php;
    root  /home/wwwroot/zig.exile.cc;
    ssl on; 		ssl_certificate   /usr/local/nginx/cert/2173934_zig.exile.cc.pem;
    ssl_certificate_key  /usr/local/nginx/cert/2173934_zig.exile.cc.key;
    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on; 		include rewrite/thinkphp.conf;
    include enable-php-pathinfo.conf; 		if (!-e $request_filename) {
            rewrite ^(.*)$ /index.php$1 last;
   } 	location ~ \.php{
            fastcgi_pass unix:/tmp/php-cgi.sock;

            fastcgi_index index.php;

            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

            include fastcgi_params;
    }

 
   
    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/zig.exile.cc.log;
  }

重启nginx
访问https://zig.exile.cc
搞定

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值