服务器维护,服务器代维,安全设置,漏洞扫描,入侵检测服务

运维之家

 找回密码
 注册
搜索
查看: 4415|回复: 0

Nginx的“虚拟目录”支持php配置

[复制链接]
dirtysea 发表于 2010-7-10 22:13:45 | 显示全部楼层 |阅读模式
Nginx出了官方的Windows版,这两天在本机装一个开发环境,需要用到类似Apache虚拟目录的情况。遇到了一些问题,上网看了很久,找了一些资料,没有看到合适的解决方法,后来想到是非php文件可以浏览,应该是$document_root的值有问题,于是做下设置,成功。。


#user nobody;
worker_processes 1;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid        logs/nginx.pid;

events {
    worker_connections 1024;
}


http {
    include       mime.types;
    default_type application/octet-stream;

    #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log logs/access.log main;
    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout 0;
    keepalive_timeout 65;

    #gzip on;
    server {
        listen       80;
        server_name localhost;

        location / {
            root   d:/dev/wwwroot/default;
            index index.php index.html index.htm;
        }
  
       location /foo {
            root   d:/dev/wwwroot;
            index index.php index.html index.htm;  
       }  

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


        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
           root d:/dev/wwwroot/default;
          if ( $uri ~ ^/foo/ ) {
               root d:/dev/wwwroot;
           }
   
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index index.php;
            include        fastcgi_params;
        }
    }
}

我的实际目录情况
d:\dev\wwwroot
                       ├─default     网站的根目录
                       └─foo           foo目录

访问
http://localhost -> default下内容
http://localhost/foo/ 对应foo下内容

fastcgi_params文件内容

fastcgi_param SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param QUERY_STRING       $query_string;
fastcgi_param REQUEST_METHOD     $request_method;
fastcgi_param CONTENT_TYPE       $content_type;
fastcgi_param CONTENT_LENGTH     $content_length;
fastcgi_param SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param REQUEST_URI        $request_uri;
fastcgi_param DOCUMENT_URI       $document_uri;
fastcgi_param DOCUMENT_ROOT      $document_root;
fastcgi_param SERVER_PROTOCOL    $server_protocol;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE    nginx/$nginx_version;
fastcgi_param REMOTE_ADDR        $remote_addr;
fastcgi_param REMOTE_PORT        $remote_port;
fastcgi_param SERVER_ADDR        $server_addr;
fastcgi_param SERVER_PORT        $server_port;
fastcgi_param SERVER_NAME        $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS    200;
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|小黑屋|手机版|Archiver|运维之家

GMT+8, 2024-4-20 09:53 , Processed in 0.192926 second(s), 14 queries .

Powered by Dirtysea

© 2008-2020 Dirtysea.com.

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