首頁  >  文章  >  運維  >  nginx中怎麼配置pathinfo模式

nginx中怎麼配置pathinfo模式

WBOY
WBOY轉載
2023-05-12 19:52:041352瀏覽

緣由

很久不使用apache了,漸漸對apache感到陌生,因為朋友有個zendframework框架從apache移到nginx下,需要pathinfo模式支援。

網上海搜

於是開始搜尋nginx pathinfo相關文章,一開以為很容易就會配置好。因為搜尋後發現有大量文章介紹nginx開啟pathinfo模式,感覺不是什麼難事。但是經過幾個小時下來,還是沒有配置好。而且大量文章的內容都極為相似,基本上都是轉載的。
開始有點急了!因為一天過去了沒有配好。

繼續摸索

沒辦法,繼續搜尋。為了驗證方便,我用a.com下載thinkphp框架搭了個環境。並且加了useraction.class.php控制器類,在類別裡加了一個app方法並輸出一行文字。
於是,我開始不斷改寫nginx.conf檔案重啟nginx,不斷的刷新a.com/index.php/user/app 位址。結果不是地址損壞提示、502、access defind.
又是一天過去了,開始感覺有點彷。

最後堅持

按理說我感覺應該有nginx thinkphp的先例,只是我沒有搜尋到答案而已。突然間覺得網路上好迷茫,一個小小的問題尋求不到解答。今晚,又試著用nginx thinkphp關鍵字搜索,我一下點到十多頁以後,找到一處代碼

複製代碼 代碼如下:

location / {       
    if (!-e $request_filename) {
        rewrite  ^/(.*)$  /index.php/$1  last;
   
 
location ~ \.php {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    include fcgi.conf努;##gi_c set _name name (. ?\.php)(/. )$") {
        set $real_script_name $1;
        set $path_info $2;
  # }_$cm fastcgi_param script_name $real_script_name;
    fastcgi_param path_info $path_info;
}


##已儲存修改,重新啟動nginx,刷新瀏覽器
意想不到的頁面出現了


#居然能訪問了,終於鬆了一口氣,實在太不容易了。
貼出nginx.conf程式碼:

複製程式碼 程式碼如下:nginx中怎麼配置pathinfo模式

user www www;
worker_processes 2;
worker_cpu_affinity 01 10;

error_log /data1/logs/nginx_error.log  crit;
 
pid webserver /nginx/nginx.pid;
 
worker_rlimit_nofile 65535;
 
events
#{
 使用epoll;
 worker_connections 65535;
## #http
{
 包含       mime.types;
 default_type application/octet-stream;
 
# server_names_hash_bucket_size 128128;
## server_names_hash_bucket_size 128128;##; 2k;
 client_max_body_size 8m;
 
  sendfile on;
  tcp_nopush     on;
 
  keepalive_time cgi_send_timeout 300;
  fastcgi_read_timeout 300 ;
  fastcgi_buffer_size 64k;
  fastcgi_buffers 4 64k;
  fastcgi_busy_buffers_size#128k;
  fastcgi_busy_buffers_size#128k;##1_fast,fastc  {
    Listen 80;
    server_name a.com ;
    索引index.php;
    root /data0/htdocs/a.com/www;
 
     name) {
            重寫  ^ /(.*)$     }
    
    地點~ \.php {
        fastcgi_pass 127.0 .0.1:9000;
        fastcgi_index index.php;
        include fcgi.conf;
        include fcgi.conf;
    if ($fastcgi_script_name ~ "^(. ?\.php)(/. )$") {
           param script_filename $document_root$real_script_name;
        fastcgi_param script_name $real_script_name ;
        fastcgi_param path_info $path_info;
    }
  }
}

#

以上是nginx中怎麼配置pathinfo模式的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:yisu.com。如有侵權,請聯絡admin@php.cn刪除