• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Nginx Alias 无法解析PHP的解决方法

php 搞代码 4年前 (2022-01-24) 13次浏览 已收录 0个评论

Nginx Alias 无法解析PHP的解决办法

Nginx Alias 无法解析PHP的解决办法:

server {
??????? listen?????? 80;
??????? server_name? xxxx.com.cn;

??????? error_log? /tmp/eror.log;
??????? set $www_root /home/web/yqbb/bgskk;

??????? location / {
??????????? root?? $www_root;
??????????? index? index.html index.php;
??????? }

??????? location /feedback {
??????????? index? index.php;
??????????? alias /home/web/yqbb/bgskk/app/htdocs;
??????? }

??????? error_page?? 500 502 503 504? /50x.html;
??????? location = /50x.html {
??????????? root?? html;
??????? }

??????? location ~ ^/feedback/.+\.php$ {
??????????????? root /home/web/yqbb/bgskk/app/htdocs;
??????????????? rewrite /feedback/(.*\.php?) /$1 break;
??????????????? include fastcgi.conf;
??????????????? fastcgi_pass?? 127.0.0.1:9000;
??????????????? fastcgi_index? index.php;
??????????????? fastcgi_param SCRIPT_FILENAME /home/web/yqbb/bgskk/app/htdocs/$fastcgi_script_name;
??????? }

??????? location ~ .*\.(php|php5)?$ {
??????????????? fastcgi_pass? 127.0.0.1:9000;
??????????????? fastcgi_index index.php;
??????????????? include fastcgi.conf;
??????? }

??? }

?

?

server
??? {
??????? listen 80;? #端口号
??????? server_name http://www.linuxidc.com;?? #域名
??????? index index.html index.htm index.php index.shtml;本文来源gao@daima#com搞(%代@#码@网&搞gaodaima代码? #默认首页
??????? root? /var/www/html;? #网站根目录
??????? charset gbk;??? #默认编码

??????? location /public/? #设定要重写的目录名
??????? {
??????????????? alias /var/www/public/; #重定向目的目录。

??????????????? #例:如果用户访问http://www.linuxidc.com/public/test.html 不会访问/var/www/html/public/test.html,而访问的是/var/www/public/test.html,虽然这个文件并没有在域名目录下
??????? }

#做完上面的设置后,我们发现访问PHP文件http://www.linuxidc.com/public/test.php时,还是去访问了/var/www/html/public/test.php,也就是说访问php文件没有起到重定向的作用,所以我们还要配置如下这段

#start

??????? location ~ ^/public/.+\.php$
??????? {
??????????????? root /var/www/html/web/news/public;
??????????????? rewrite /public/(.*\.php?) /$1 break;
??????????????? include fastcgi.conf;
??????????????? fastcgi_pass?? 127.0.0.1:9000;
??????????????? fastcgi_index? index.php;
??????? }

#end

??????? location ~ .*\.(php|php5)?$
??????? {
??????????? #fastcgi_pass? unix:/tmp/php-cgi.sock;
??????????? fastcgi_pass? 127.0.0.1:9000;
??????????? fastcgi_index index.php;
??????????? #include fcgi.conf;
??????????? include fastcgi.conf;
??????????? rewrite? ^/([a-zA-Z]+)\/([a-zA-Z]+)$ /$2.shtml last;
??????? }

??????? location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
??????? {
??????????? expires????? 30d;? #缓存30天
??????? }

??????? location ~ .*\.(js|css)?$
??????? {
??????????? expires????? 1h; #缓存1个小时
??????? }

??????? access_log? /var/log/linuxidc.log? access;? #定义日志文件
??????? ssi on;
??????? ssi_silent_errors on;
??????? ssi_types text/shtml;
??? }


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Nginx Alias 无法解析PHP的解决方法
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址