zoukankan      html  css  js  c++  java
  • windows 下 nginx 配置虚拟主机

    1. 在 nginx 的配置文件 nginx.conf 里面 引入虚拟主机配置文件,以后所有的虚拟主机配置文件都在写这个文件里

      include       vhost.conf;

      (或者新建vhost目录,每个虚拟主机用一个配置文件,这样就得这样引入配置文件 include     vhost/*.conf)

    2. 在 conf 目录下面新建 vhost.conf 文件

      

    server {
        listen 80;
        server_name youyi.localhost.com;
    
        location / {
            root E:/svn/youyi/youyi;
            index index.php index.html index.htm;
        }
    
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    
        location ~ .php(.*)$ {
            root           E:/svn/youyi/youyi;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME $document_root/$fastcgi_script_name;
            include        fastcgi_params;
        }
    }

      listen 监听 80 端口

      server_name 虚拟主机域名

      location 下的root 配置虚拟主机访问的路径,index 配置默认访问首页

      以上是设置能运行php的基础配置

      现在运行youyi.localhost.com/index.php 能正常访问,但是这样配置还不能满足我们的需求,比如,如果我们访问youyi.localhost.com/index.php/admin/ nginx 就会返回错误。因为 nginx 不支持 PATH_INFO的访问方式,那怎么办呢,我们用一下方式解决

      将location .php 配置改成这样:

      

        location ~ .php(.*)$ {
            root           E:/svn/youyi/youyi;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info ^(.+.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;
        }

       这样就能支持pathinfo 路径访问了

    参考文献:http://www.nginx.cn/426.html

    (注:该文献里面的fastcgi_split_path_info 配置是这样的 ^((?U).+.php)(/?.+)$ ,但是作者在使用过程中遇到一个问题:youyi.localhost.com/a/b/c.php 这样的路径返回 403 Access denied ,经过查找资料改成以上写法就可以了

  • 相关阅读:
    147-21. 合并两个有序链表
    146-14. 最长公共前缀
    145-如何查看python帮助文档
    144-38. 外观数列
    143-121. 买卖股票的最佳时机
    142-206. 反转链表
    141-98. 验证二叉搜索树
    Nginx中文域名配置
    Keepalived+Nginx架构整理版
    Tomcat启动脚本
  • 原文地址:https://www.cnblogs.com/songlen/p/7424376.html
Copyright © 2011-2022 走看看