nginx服务器虚拟主机配置详解

server {

    listen      80;                                                                                              #监听80端口

    server_name  baidu.com;                                                                         #域名

    root    "D:/phpStudy/PHPTutorial/WWW/smartcard/public";                     #项目根目录表示用该服务器访问该域名时会访问到

    index  index.html index.htm index.php;                                                     #这个目录下面的index index.html index.htm                                                                                                                                    #index.php 文件

    error_page  500 502 503 504  /50x.html;                                                   #服务器出错后会调用public/500.html等页面

    location = /50x.html {                                                                                   

        root  html;

    }

    location / {                                                                                                    #在Nginx低版本中,是不支持PATHINFO的,但是                                                                                                                           #可以通过在Nginx.conf中配置转发规则实现:

                if (!-e $request_filename){

                    rewrite  ^/(.*)$  /index.php?s=/$1  last;

          }

}

    location ~ \.php(.*)$  {

        fastcgi_pass  127.0.0.1:9000;

        fastcgi_index  index.php;

        fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;

        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name; #脚本文件请求的路径

        fastcgi_param  PATH_INFO  $fastcgi_path_info;                                              #可自定义变量

        fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;

        include        fastcgi_params;

    }

}

你可能感兴趣的:(nginx服务器虚拟主机配置详解)