博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
074 TP5 Nginx 打开都是找不到文件(404)(开启pathinfo)
阅读量:3606 次
发布时间:2019-05-21

本文共 3542 字,大约阅读时间需要 11 分钟。

在windows环境下正常

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

 Nginx系统是通过OneinStack来安装的

这是因为
ThinkPHP需要pathinfo的支持,

开启pathinfo办法

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

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

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

原代码:

[html]   
  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]   
  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/

你可能感兴趣的文章
面试官:Kafka 如何优化内存缓冲机制造成的频繁 GC 问题?
查看>>
【基于日均百万交易的订单系统】从 0 开始带你成为消息中间件实战高手!
查看>>
面试官:每秒上千订单的场景下,如何对分布式锁进行高并发优化?
查看>>
如何设计一个电商平台积分兑换系统?
查看>>
fastjson 漏洞导致服务瘫痪?先别忙升级,真相是它!
查看>>
产品经理相亲图鉴
查看>>
Redis 分布式锁的正确实现方式(Java版)
查看>>
Redis 到底是怎么实现“附近的人”这个功能的?
查看>>
最近面试 Java 后端开发的感受以及给候选人的一些建议!
查看>>
一个日均百万交易订单系统的整体架构、业务流程及负载情况?
查看>>
ArrayList 插入1000万条数据之后,我怀疑了jvm...
查看>>
【案例分析】分布式系统的接口幂等性设计!
查看>>
从一个程序员的角度告诉你:“12306”有多牛逼?
查看>>
MySQL 性能优化:8 种常见 SQL 错误用法!
查看>>
什么是读写锁?微服务注册中心是如何进行读写锁优化的?
查看>>
记一次神奇的 sql 查询经历,group by 慢查询优化!
查看>>
Java 如何设计 API 接口,实现统一格式返回?
查看>>
写代码做副业月入10k的方法都藏在这几个腾讯、阿里大佬的公众号里!
查看>>
这样讲 API 网关,你应该能明白了吧!
查看>>
从实践角度重新理解 BIO 和 NIO
查看>>