[英]rewrite rules for nginx and Codeigniter
我已經在codeigniter中實現了一個php應用程序,現在想將其部署到nginx服務器。 部署之前,我使用MAMP服務器在本地主機上檢查了nignx配置。 它工作正常。 但是,此配置在實時服務器上不起作用。 作為nginx的初學者,我不明白這里的錯誤在哪里。 在實時服務器中,我無法寫入主nginx.conf文件。 我的應用程序“ abc”有一個單獨的配置文件,如“ abc”。 我所有的應用程序文件都在“ abc / xyz”目錄下。 這是我的樣本配置,
location /abc {
root /srv/www/htdocs/apps/;
index index.html index.htm index.php;
location /xyz {
try_files $uri $uri/ /abc/xyz/index.php;
}
location ~ \.php(\/(\w+))*$ {
try_files $uri =404;
rewrite (.+)\.php(\/(\w+))*$ $1.php break;
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
在這里,我可以看到我的歡迎頁面https:// myapplication / abc / xyz 。 但是,如果我要瀏覽其他頁面,例如https:// myapplication / abc / xyz / other_pages ,則會顯示“ 404頁面未找到”。 我已經檢查了其他解決方案,但是在這種情況下它們都不起作用。 先謝謝您的幫助!
location /xyz
塊嵌套在location /abc
塊內。 需要嵌套塊來處理具有/abc/xyz
前綴的URI。
如果您的location /abc
塊周圍還有其他正則表達式 location
塊, you should use the
^〜`修飾符。
例如:
location ^~ /abc {
...
location /abc/xyz {
...
}
...
}
有關更多信息,請參見此文檔 。
抱歉回復晚了。 這實際上是非常愚蠢的錯誤。 我的控制器頁面名稱是小寫字母。 這就是為什么它不起作用。 我的配置還可以。 控制器頁面的首字母應為大寫字母。 例如,我的控制器名稱是Home。 所以我的php文件名必須是Home.php而不是home.php。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.