2016-04-07 55 views
0

我正在從Apache遷移到nginx,需要將大量的httaccess文件轉換爲nginx格式。nginx重寫2種方法的區別

  1. 我發現2種方式工作,我應該使用哪一種?

    location = /test.html { rewrite ^(.*)$ /index.php?action=temp&name=test; } 
    

    或只是

    rewrite ^/test.html$ /index.php?action=temp&name=test; 
    
  2. 我把所有這一切在文件(ez_rewrite_list.conf),然後包括在virtual.conf。我應該在哪裏放置文件位置?有關係嗎?我做對了嗎?任何提示

    server { 
        listen  80; 
        server_name test.com; 
    
        location/{ 
         root /var/www/com/mysite; 
         index index.php index.html index.htm; 
        } 
    
        include /etc/nginx/ez_conf/ez_rewrite_list.conf; 
    
    
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
        # 
        location ~ \.php$ { 
         root   /var/www/com/mysite; 
         fastcgi_pass 127.0.0.1:9000; 
         fastcgi_index index.php; 
         fastcgi_param SCRIPT_FILENAME document_root$fastcgi_script_name; 
         include  fastcgi_params; 
        }  
    } 
    

回答

2

你忘了逃避重寫點(.),他們是不完全一樣的。

技術上的確切位置應該比檢查每個請求的正則表達式快一點。你也不必捕捉裏面的位置重寫任何東西,所以我會用

location = /test.html { 
    rewrite^/index.php?action=temp&name=test; 
} 

但實際上,你永遠不會看到任何區別。

+0

明白了,謝謝 – bell2041