074 TP5 Nginx 打开都是找不到文件(404)(开启pathinfo)

在windows环境下正常

上传到服务器Nginx,除了首页能打开外,其它都不能打开,打开都是找不到文件

 Nginx系统是通过OneinStack来安装的
这是因为
ThinkPHP需要pathinfo的支持,

开启pathinfo办法


找到对应虚拟空间的配置文件

路径:/usr/local/nginx/conf/vhost/cms.xxxx.vip.conf

文件中找到对应那个虚拟目录 (每个人的服务器可能不相同)

原代码:

[html]  view plain  copy
  1. server {  
  2.   listen 80;  
  3.   server_name cms.xxxx.vip;  
  4.   access_log /data/wwwlogs/cms.xxxx.vip_nginx.log combined;  
  5.   index index.html index.htm index.php;  
  6.   include /usr/local/nginx/conf/rewrite/none.conf;  
  7.   root /data/wwwroot/default/cms.xxx.vip/public;  
  8.     
  9.   #error_page 404 = /404.html;  
  10.   #error_page 502 = /502.html;  
  11.     
  12.   location ~ [^/]\.php(/|$) {  
  13.     #fastcgi_pass remote_php_ip:9000;  
  14.     fastcgi_pass unix:/dev/shm/php-cgi.sock;  
  15.     fastcgi_index index.php;  
  16.     include fastcgi.conf;  
  17.   }  
  18.   location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {  
  19.     expires 30d;  
  20.     access_log off;  
  21.   }  
  22.   location ~ .*\.(js|css)?$ {  
  23.     expires 7d;  
  24.     access_log off;  
  25.   }  
  26.   location ~ /\.ht {  
  27.     deny all;  
  28.   }  
  29. }  

修改成:


[html]  view plain  copy
  1. server {  
  2.   listen 80;  
  3.   server_name cms.xxxx.vip;  
  4.   access_log /data/wwwlogs/cms.xxxx.vip_nginx.log combined;  
  5.   index index.html index.htm index.php;  
  6.   include /usr/local/nginx/conf/rewrite/none.conf;  
  7.   root /data/wwwroot/default/cms.xxxx.vip/public;  
  8.     
  9.   #error_page 404 = /404.html;  
  10.   #error_page 502 = /502.html;  
  11.     
  12. if (!-e $request_filename) {  
  13.         rewrite ^/(.*)$ /index.php/$1 last;  
  14.         break;  
  15.         }  
  16.   
  17. location ~ [^/]\.php(/|$) {  
  18.         fastcgi_split_path_info ^(.+\.php)(/.+)$;  
  19.         try_files $fastcgi_script_name =404;  
  20.         set $path_info $fastcgi_path_info;  
  21.         fastcgi_param PATH_INFO $path_info;  
  22.         fastcgi_pass unix:/dev/shm/php-cgi.sock;  
  23.         fastcgi_index index.php;  
  24.         include fastcgi.conf;  
  25.         }  
  26.   location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {  
  27.     expires 30d;  
  28.     access_log off;  
  29.   }  
  30.   location ~ .*\.(js|css)?$ {  
  31.     expires 7d;  
  32.     access_log off;  
  33.   }  
  34.   location ~ /\.ht {  
  35.     deny all;  
  36.   }  
  37. }  

参考:

erver {
listen 443 ssl spdy;
ssl_certificate 1_ss.linuxeye.com_bundle.crt;
ssl_certificate_key ss.linuxeye.com.key;
ssl_ciphers "CHACHA20:GCM:HIGH:!DH:!RC4:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS";
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 5s;
server_name ss.linuxeye.com;
access_log off;
index index.html index.htm index.jsp index.php;
root /home/wwwroot/ss.linuxeye.com;


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


location ~ [^/]\.php(/|$) {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        try_files $fastcgi_script_name =404;
        set $path_info $fastcgi_path_info;
        fastcgi_param PATH_INFO $path_info;
        fastcgi_pass unix:/dev/shm/php-cgi.sock;
        fastcgi_index index.php;
        include fastcgi.conf;
        }



location ~ /\.ht {
        deny  all;
        }


location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
        expires 30d;
        }


location ~ .*\.(js|css)?$ {
        expires 7d;
        }
}

引用:https://oneinstack.com/question/313/


将虚拟主机配置文件/usr/local/nginx/conf/vhost/www.example.com.conf中:

    #fastcgi_pass remote_php_ip:9000;
    fastcgi_pass unix:/dev/shm/php-cgi.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    set $real_script_name $fastcgi_script_name;
        if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
        set $real_script_name $1;
        set $path_info $2;
        }
    fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
    fastcgi_param SCRIPT_NAME $real_script_name;
    fastcgi_param PATH_INFO $path_info;
    }

改成如下:

    #fastcgi_pass remote_php_ip:9000;
    fastcgi_pass unix:/dev/shm/php-cgi.sock;
    fastcgi_index index.php;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    fastcgi_param PATH_INFO $fastcgi_path_info; 
    include fastcgi_params;
    }

重新加载nginx

service nginx reload



引用:https://oneinstack.com/question/785/

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值