074 TP5 Nginx 開啟都是找不到檔案(404)(開啟pathinfo)
在windows環境下正常
上傳到伺服器Nginx,除了首頁能開啟外,其它都不能開啟,開啟都是找不到檔案
Nginx系統是通過OneinStack來安裝的
這是因為
ThinkPHP需要pathinfo的支援,
開啟pathinfo辦法
找到對應虛擬空間的配置檔案
路徑:/usr/local/nginx/conf/vhost/cms.xxxx.vip.conf
檔案中找到對應那個虛擬目錄 (每個人的伺服器可能不相同)
原始碼:
- server {
- listen 80;
- server_name cms.xxxx.vip;
- access_log /data/wwwlogs/cms.xxxx.vip_nginx.log combined;
- index index.html index.htm index.php;
- include /usr/local/nginx/conf/rewrite/none.conf;
- root /data/wwwroot/default/cms.xxx.vip/public;
- #error_page 404 = /404.html;
- #error_page 502 = /502.html;
- location ~ [^/]\.php(/|$) {
- #fastcgi_pass remote_php_ip:9000;
- fastcgi_pass unix:/dev/shm/php-cgi.sock;
- fastcgi_index index.php;
- include fastcgi.conf;
- }
- location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
- expires 30d;
- access_log off;
- }
- location ~ .*\.(js|css)?$ {
- expires 7d;
- access_log off;
- }
- location ~ /\.ht {
- deny all;
- }
- }
修改成:
- server {
- listen 80;
- server_name cms.xxxx.vip;
- access_log /data/wwwlogs/cms.xxxx.vip_nginx.log combined;
- index index.html index.htm index.php;
- include /usr/local/nginx/conf/rewrite/none.conf;
- root /data/wwwroot/default/cms.xxxx.vip/public;
- #error_page 404 = /404.html;
- #error_page 502 = /502.html;
- 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 ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
- expires 30d;
- access_log off;
- }
- location ~ .*\.(js|css)?$ {
- expires 7d;
- access_log off;
- }
- location ~ /\.ht {
- deny all;
- }
- }
參考:
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/