1. 程式人生 > >074 TP5 Nginx 開啟都是找不到檔案(404)(開啟pathinfo)

074 TP5 Nginx 開啟都是找不到檔案(404)(開啟pathinfo)

在windows環境下正常

上傳到伺服器Nginx,除了首頁能開啟外,其它都不能開啟,開啟都是找不到檔案

 Nginx系統是通過OneinStack來安裝的
這是因為
ThinkPHP需要pathinfo的支援,

開啟pathinfo辦法

找到對應虛擬空間的配置檔案

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

檔案中找到對應那個虛擬目錄 (每個人的伺服器可能不相同)

原始碼:

  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.   #error_page 404 = /404.html;  
  9.   #error_page 502 = /502.html;  
  10.   location ~ [^/]\.php(/|$) {  
  11.     #fastcgi_pass remote_php_ip:9000;  
  12.     fastcgi_pass unix:/dev/shm/php-cgi.sock;  
  13.     fastcgi_index index.php;  
  14.     include fastcgi.conf;  
  15.   }  
  16.   location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {  
  17.     expires 30d;  
  18.     access_log off;  
  19.   }  
  20.   location ~ .*\.(js|css)?$ {  
  21.     expires 7d;  
  22.     access_log off;  
  23.   }  
  24.   location ~ /\.ht {  
  25.     deny all;  
  26.   }  
  27. }  

修改成:


  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.   #error_page 404 = /404.html;  
  9.   #error_page 502 = /502.html;  
  10. if (!-e $request_filename) {  
  11.         rewrite ^/(.*)$ /index.php/$1 last;  
  12.         break;  
  13.         }  
  14. location ~ [^/]\.php(/|$) {  
  15.         fastcgi_split_path_info ^(.+\.php)(/.+)$;  
  16.         try_files $fastcgi_script_name =404;  
  17.         set $path_info $fastcgi_path_info;  
  18.         fastcgi_param PATH_INFO $path_info;  
  19.         fastcgi_pass unix:/dev/shm/php-cgi.sock;  
  20.         fastcgi_index index.php;  
  21.         include fastcgi.conf;  
  22.         }  
  23.   location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {  
  24.     expires 30d;  
  25.     access_log off;  
  26.   }  
  27.   location ~ .*\.(js|css)?$ {  
  28.     expires 7d;  
  29.     access_log off;  
  30.   }  
  31.   location ~ /\.ht {  
  32.     deny all;  
  33.   }  
  34. }  

參考:

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/