[英]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.