nginx代理httpd(mod_php)时yii2的url美化问题
来源:互联网 发布:ubuntu软件中心搜索框 编辑:程序博客网 时间:2024/06/04 17:53
每次到cdsn写博客时,肯定是全网都搜不到解决方案的,哎。
比如我要把 /index.php?r=site/about 改为 /site/about.html
yii2的url美化问题解决方案一搜一大把,nginx转php-fpm的也有,单用apache的也有(.htaccess),但偏偏没有怎样设置nginx代理httpd(mod_php)的情况。我试了N久都是404错误,后来通过对比enablePrettyUrl为true和false的两种情况,发现要想让yii2能正常识别url,关键就是SERVER信息中的REQUEST_URI必须要正确,比方说要为/site/about.html 这样。因此nginx中不能用try_files来改写url到index.php,否则转发到后端的httpd时,识别出来的REQUEST_URI就是index.php,而不是 /site/about.html
不废话了,上配置:
Yii2:
'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'suffix' => '.html', 'rules' => [ ], ],
Ngnix:
注意!这里对location /不像普遍的那个答案,用try_files,而是直接转发给后端的apache,让它处理
location / { proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Protocol $scheme; proxy_set_header PATH-INFO $request_uri; proxy_pass http://$ups; } location ~ \.php$ { try_files $uri =404; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Protocol $scheme; proxy_set_header PATH-INFO $request_uri; proxy_pass http://$ups; }
Apache:
放在.htaccess中也可以,但放httpd.conf中效率更高些
<VirtualHost *:99> ServerName www1.tq.com DocumentRoot "/www/tq/www/web" <Directory "/www/tq/www/web"> Options FollowSymLinks MultiViews DirectoryIndex index.php index.html RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.php AllowOverride None Order allow,deny Allow from all Require all granted </Directory></VirtualHost>
0 0
- nginx代理httpd(mod_php)时yii2的url美化问题
- Yii2的URL美化
- 关于yii2的url美化及相关apache配置问题
- Yii2.0美化路由Url
- yii2框架-伪静态的配置/美化URL
- nginx的重写和url美化
- Yii2框架Nginx配置以及修改fastcgi.conf实现URL美化
- YII2设置路由访问,美化url
- yii2.0系列三:url美化
- YII2.0-advanced-4—URL美化
- [路由] -- Yii2 url地址美化与重写
- yii2.0域名目录绑定(二级域名)以及url美化 url伪静态 Apache 和 IIS
- qeephp url美化之后的 SEO问题
- yii2 urlManager url美化及apache下yii2 rewrite设置
- Nginx 配置反向代理后,页面中取绝对URL地址的问题显示代理端口
- Yii2 路由之同时支持 URL 原始和美化的请求 [ 2.0 版本 ]
- httpd的url匹配
- Thinkphp的URL美化
- DEBIN GDM 选择多种桌面
- UML四种关系简介
- 利用大白菜制作多系统启动U盘(win+ubuntu+PE+...)
- 使用MockMvc测试Spring mvc Controller
- 用最科学的方法展示最形象的图表——前端数据可视化实践
- nginx代理httpd(mod_php)时yii2的url美化问题
- mysql自动按时间分区实例
- python3处理剧本角色台词分开输出
- "error while loading shared libraries: xxx.so.x"
- Malloc Debug & Native Memory Tracking using libc Callbacks
- 软键盘 ListView中包含EditText 重绘 ,失去焦点
- Junit测试Controller(MockMVC使用),传输@RequestBody数据解决办法
- 关于屏幕适配
- block总结