PHP/FastCGI 示例

作者:csuper 发表于:2010-10-07

somaceo配置的一个示例,nginx版本为windows 编译版本 nginx-0.7.64,解决了alias 虚拟目录不支持运行php的问题,该版本可以使用中文文件名、中文目录、windows的文件名格式、驱动器盘符等。示例是一个discuz论坛及uchomephp程序网站。

PHP/FastCGI 示例

#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   dabao.imbbs.in;
        #下面两行是路径后面自动加上/
        root   H:\APMServ526\www\Dis\uc_home;
        if (-d $request_filename) {rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;}

        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {
            root   H:\APMServ526\www\Dis\uc_home;
            index  index.php index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        #=======虚拟目录也支持php
            location /bbs {
             alias H:\APMServ526\www\dis;
             index index.php index.html index.htm;
             }
             location ~ ^/bbs/.+\.php$ {
             #location /bbs/.+\.php$ {
             root H:\APMServ526\www\dis;
             rewrite /bbs/(.*\.php?) /$1 break;
             include        fastcgi_params;
             fastcgi_pass   127.0.0.1:9000;
             fastcgi_index  index.php;
             fastcgi_param SCRIPT_FILENAME H:\APMServ526\www\dis$fastcgi_script_name;
             }
#==========
#-------
        location /uc {
        alias H:\APMServ526\www\dis\uc;
        index index.php index.html index.htm;
       # autoindex on;
       # autoindex_exact_size on;
        }
    
#-------

        location /dis {
        alias H:\APMServ526\www\dis;
        index index.php index.html index.htm;
   
        autoindex on;
       # autoindex_exact_size on;
        }
                   
        location /dis/attachments/dvbbs {
        alias H:\WWW\DV82UTF-8\UploadFile;
 
     # autoindex on;
       # autoindex_exact_size on;
        }
      location /bbs/attachments/dvbbs {
        alias H:\WWW\DV82UTF-8\UploadFile;
 
        }
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
       # location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
       # }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
            location ~ \.php$ {
           root   H:\APMServ526\www\Dis\uc_home;
         if ( $uri ~ ^/uc/ ) {
             root H:\APMServ526\www\dis;
           }
         # if ( $uri ~ ^/dis/ ) {
         #      root H:\APMServ526\www;
         #  }
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
     
       fastcgi_param SCRIPT_FILENAME    $document_root$fastcgi_script_name;
            #fastcgi_param  SCRIPT_FILENAME    H:\APMServ526\www\Dis\uc_home$fastcgi_script_name;

            include        fastcgi_params;
        }
       #设置查看nginx的运行状态的目录/ng/
       location ~ ^/ng/ {
       stub_status on;
       access_log off;

       }
}



}

 

版权声明

本文仅代表作者观点,不代表Csuper立场。
本文系作者授权百度百家发表,未经许可,不得转载。