您的位置:首页 > 运维架构 > Nginx

nginx带SSL证书配置ThinkPHP5四级目录访问

2020-06-05 06:56 225 查看

     网上找了很多都是nginx配置ThinkPHP5二级访问的,但我这个项目开发的真的会给我出难题,搞个四级目录来让我配置!

在配置之前,我也参考了不少网络上的配置文章,想从二级直接跟着对方的配置思路去走,但就是不行,配置后提示file not found!

    我要配置的地址是:https://域名/xcx/wxapp/public/,根目录要放在域名的位置,如果是直接配置到public就很简单了,如下配置就行了。

server {

    listen       443 ssl;
    server_name  yuntong.xxx.com;

  ssl_certificate cert/yuntong.xxx.com_bundle.crt; #将yuntong.xxx.com_bundle.crt替换成您证书的文件名。
  ssl_certificate_key cert/yuntong.xxx.com.key; #将yuntong.xxx.com.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;   # 修改protocols。
  ssl_prefer_server_ciphers on;

root /usr/www/xcx/wxapp/public;
    index index.php index.html ;
    
    

      location / {
       if (!-e $request_filename) {
           rewrite  ^(.*)$  /index.php?s=/$1  last;
       }
}   
    location ~ \.php {
        include fastcgi_params;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param  PATH_INFO  $fastcgi_path_info;
        fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
    }
}

现在难题就出在下面的这段代码:

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

 

之前我看了网上的配置,把它配置成如下:

location /xcx/wxapp/public/ {
       if (!-e $request_filename) {
           rewrite  ^/xcx/wxapp/public/(.*)$  /xcx/wxapp/public/index.php?s=/$1  last;
       }

重启nginx后,还是提示file not found! 

后来我又上网专门找nginx的rewrite的用法,其中,以下这个用法给了我提示

www.myweb.com/admin/ 下跳转为www.myweb.com/admin/index.php?s=

if (!-e $request_filename){

rewrite ^/admin/(.*)$ /admin/index.php?s=/$1 last;

    }

原来重定向不设置 location,我之前就所以不成功,可能参考网上的做法,于是我把代码改成这样

server {

    listen       443 ssl;
    server_name  yuntong.xxx.com;

  ssl_certificate cert/yuntong.xxx.com_bundle.crt; #将yuntong.xxx.com_bundle.crt替换成您证书的文件名。
  ssl_certificate_key cert/yuntong.xxx.com.key; #将yuntong.xxx.com.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;   # 修改protocols。
  ssl_prefer_server_ciphers on;

root /usr/www;
    index index.php index.html ;

location / {
       if (!-e $request_filename) {
           rewrite  ^/xcx/wxapp/public/(.*)$  /xcx/wxapp/public/index.php?s=/$1  last;
       }

location ~ \.php {
        include fastcgi_params;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param  PATH_INFO  $fastcgi_path_info;
        fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
    }
}

然后奇迹终于出现了,在centos7.8.2下的LNMP环境中,成功把Thinkphp5的四级目录配置完成了!

这次配置使我发现,网上太多东西都是一样的,但很多都用不上,成功还得靠自己努力!

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: