VPS侦探论坛

 找回密码
 注册
查看: 14395|回复: 15

请教军哥个问题,Nginx下能不能设置虚拟目录

[复制链接]
发表于 2014-8-10 16:01:47 | 显示全部楼层 |阅读模式

Nginx下能不能设置虚拟目录,并支持php,试了好多次,都不能成功支持php
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2014-8-10 20:08:20 | 显示全部楼层


可以设置,但必须也得按原来的配置加上php解析才能行
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
 楼主| 发表于 2014-8-11 10:50:56 | 显示全部楼层

location ~ /abc/.+.php$ {
root /home/;
rewrite /abc/(.*.php) /$1 break;
include fastcgi_params;
fastcgi_pass  unix:/tmp/php-fcgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/abc/$fastcgi_script_name;}

location ~ /abc/(.*)$ {
alias /home/abc/$1;
}

这样设置只支持静态html ,php死活解析不了!
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2014-8-11 16:39:19 | 显示全部楼层



  1. location /test {
  2. alias /home/wwwroot/test/;
  3. index index.html index.php;
  4. }

  5. location ~ /test/.+\.php$ {
  6. rewrite /test/(.+\.php) /$1 break;
  7. fastcgi_pass  unix:/tmp/php-cgi.sock;
  8. fastcgi_index  index.php;
  9. fastcgi_param  SCRIPT_FILENAME  /home/wwwroot/test/$fastcgi_script_name;
  10. include  fastcgi_params;
  11. }
复制代码

最重要的一点,这个要放在对应虚拟主机php那个location的前面
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
 楼主| 发表于 2014-8-12 17:27:57 | 显示全部楼层

这样设置后,出现
502 Bad Gateway
错误了

军哥运维代购:http://shop63846532.taobao.com/

发表于 2014-8-12 17:46:53 | 显示全部楼层

修改过php-fpm的套接字配置?
 楼主| 发表于 2014-8-12 19:36:57 | 显示全部楼层

php-fpm,配置都没有改过啊
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2014-8-12 20:36:03 | 显示全部楼层

回复 7# 的帖子


我发的配置没问题,已经测试过了,你贴上你整个虚拟主机的配置文件看看
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
 楼主| 发表于 2014-8-13 00:06:49 | 显示全部楼层


俺不是在虚拟主机的配置加的代码,而是在主配置(/usr/local/nginx/conf/nginx.conf)里加虚拟目录的
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2014-8-13 08:07:40 | 显示全部楼层

回复 9# 的帖子




贴整个server段配置
 楼主| 发表于 2014-8-13 10:51:54 | 显示全部楼层

回复 10# 的帖子


server
        {
                listen 80 default;
                #listen [::]:80 default ipv6only=on;
                server_name localhost;
                index index.html index.htm index.php;
                root  /web/wwwww;

location /test {
alias /home/test/;
index index.html index.php;
}

location ~ /test/.+\.php$ {
rewrite /test/(.+\.php) /$1 break;
fastcgi_pass  unix:/tmp/php-fcgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/test/$fastcgi_script_name;
include  fastcgi_params;
}

                #error_page   404   /404.html;
                location ~ [^/]\.php(/|$)
                        {
                                # comment try_files $uri =404; to enable pathinfo
                                try_files $uri =404;
                                fastcgi_pass  unix:/tmp/php-cgi.sock;
                                fastcgi_index index.php;
                                include fastcgi.conf;
                                #include pathinfo.conf;
                        }


                location /nginx_status {
                        stub_status on;
                        access_log   off;
                }

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

                location ~ .*\.(js|css)?$
                        {
                                expires      12h;
                        }

               location ~ /\.ht {
                                 deny all;
               }

                access_log  /web/wwwlogs/access.log  access;
        }
发表于 2014-8-13 13:08:01 | 显示全部楼层

可能php-fpm启动,也可能是https://bbs.vpser.net/thread-1144-1-1.html 这里的其他原因
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
 楼主| 发表于 2014-8-13 15:48:44 | 显示全部楼层

回复 12# 的帖子

军哥!您这样试过成功吗?
看来php-fpm 真有点不稳定啊?
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2014-8-13 20:16:50 | 显示全部楼层
测试过了
http://116.251.209.38/test/p.php
http://116.251.209.38/test/d.txt

军哥运维代购:http://shop63846532.taobao.com/

 楼主| 发表于 2014-8-13 20:48:23 | 显示全部楼层
俺用的是PHP 5.2.17,不知道这个影响吗?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|VPS侦探 ( 鲁ICP备16040043号-1 )

GMT+8, 2024-9-26 01:28 , Processed in 0.030866 second(s), 16 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表