这篇文章仅仅是操作,解释说明部分待更新。

1. 修改nginx的配置文件(我的配置文件在/etc/nginx/nginx.conf)

[root@xxx ~]# find / -name nginx.conf      
[root@xxx ~]# vim /etc/nginx/nginx.conf    
nginx.conf配置文件的大致结构:
...
http{
    server{
    ...                      #一个server结构可以对应一个域名
    }
    include vhosts/*.conf;   #增加这一句,以后所有新增的域名都可以放在/etc/nginx/vhosts/下,便于分开管理,注意vhosts目录需要创建
}

2. 在/etc/nginx/vhosts/目录下,新增新域名的配置文件xincanzhe.conf(这边我要绑定一个www.xincanzhe.top的域名),复制nginx.conf中的server部分到xincanzhe.conf

server {
        listen       80;
        server_name  www.xincanzhe.top;    #新增域名名称

        #charset koi8-r;

        access_log  /data/wwwlogs/www.xincanzhe.top.log  combined;    #设置访问该域名产生的日志文件,无需创建设置后会自动生成

        location / {
            root   /data/wwwroot/xincanzhe/public/;    #域名指向的根目录
            index  index.html index.php index.htm;
            #隐藏index.php
            if (!-e $request_filename) {
                rewrite  ^(.*)$  /index.php?s=/$1  last;
                break;
            }
        }

        #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;
        }

        # 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           /data/wwwroot/xincanzhe/public/;    #域名指向的根目录
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            #使Nginx支持pathinfo路由
            fastcgi_split_path_info  ^(.+\.php)(.*)$;       #增加这一句
            fastcgi_param PATH_INFO  $fastcgi_path_info;    #增加这一句
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }

3. 如果需要再次新增域名,只需要在/etc/nginx/vhosts/新建一个配置文件即可。

4. 修改nginx配置文件记得语句后加上分号;

nginx服务器绑定多个域名、支持pathinfo路由、隐藏index.php入口文件的更多相关文章

  1. nginx支持pathinfo并且隐藏index.php

    How To Set Nginx Support PATHINFO URL Model And Hide The /index.php/ 就像这样 The URL before setting lik ...

  2. nginx 多域名配置 (nginx如何绑定多个域名)

         nginx绑定多个域名可又把多个域名规则写一个配置文件里,也可又分别建立多个域名配置文件,我一般为了管理方便,每个域名建一个文件,有些同类域名也可又写在一个总的配置文件里. 一.每个域名一个 ...

  3. codeigniter在nginx 下支持pathinfo和去除index.php的方法

    as今天准备把网站搬迁到nginx上发现codeigniter框架在nginx上不能使用,后来发现是nginx不支持pathinfo,下面介绍怎么在nginx下开启pathinfo 开始pathinf ...

  4. Nginx 虚拟主机下支持Pathinfo并隐藏入口文件的完整配置

    server { listen 80; server_name zuqiu.com; # 设置你的域名 index index.html index.htm index.php; root D:/wn ...

  5. apache2虚拟主机实现一个服务器绑定多个域名

    1.apache2的配置 首先要配置好apache2,如果未配置,请参考我之前的博文:lamp的配置 2.域名的解析 将全部域名的www和@的A记录解析到云服务器的IP 3.虚拟主机的配置 1.配置h ...

  6. apache服务器绑定泛解析域名

    <VirtualHost *:80> DocumentRoot "E:\web\bubuchu" ServerName bubuchu.com ServerAlias ...

  7. lnmp启用pathinfo并隐藏index.php

    编辑如下区段: location ~ [^/]\.php(/|$) { # comment try_files $uri =404; to enable pathinfo try_files $uri ...

  8. ThinkPHP中通过URL重写隐藏应用的入口文件index.php的相关服务器的配置

    [ Apache ] 将httpd.conf配置文件中mod_rewrite.so所在行前面的‘#’去掉 AllowOverride None 将None改为 All 效果图

  9. nginx不支持pathinfo函数

    server { listen ; server_name www.domain.com domain.com; error_page /.html; error_page /50x.html; lo ...

随机推荐

  1. 几个常见用于解决nginx负载均衡的session共享问题的办法

    查了一些资料,看了一些别人写的文档,总结如下,实现nginx session的共享: PHP服务器有多台,用nginx做负载均衡,这样同一个IP访问同一个页面会被分配到不同的服务器上,如果sessio ...

  2. gitlab容器--带https配置

    #2.gitlab 重要目录 /home/maks/gitlab/config /etc/gitlab /home/maks/gitlab/logs /var/log/gitlab /home/mak ...

  3. NASA的10条代码编写原则

    NASA的10条代码编写原则 作者: Gerard J. Holzmann 来源: InfoQ 原文链接 英文原文:NASA's 10 Coding Rules for Writing Safety ...

  4. EndNote登陆Web账号时解决不断询问用户名密码

    EndNote登陆Web账号时不断询问用户名密码怎么破?EndNote有个同步功能,在登陆Web账号时,EndNote不断的询问账号和密码,可是用户名和密码明明已经填写正确和完毕,就是登陆不上EndN ...

  5. vue打包后出现的.map文件

    run dev build 打包项目后出现的list中的".map"文件最大. “.map”文件的作用:项目打包后,代码都是经过压缩加密的,如果运行时报错,输出的错误信息无法准确得 ...

  6. DB link的迁移

    我们在做某些Schema的迁移的时候,由于用到Public的db link,然而由于不知道db link中目标端账号的密码,因此无法在新环境重新创建DB link. 本次实验的思路是将视图dba_db ...

  7. Java - 关于子类父类的向上转型,向下转型

    以下Animal为父类,Dog,Cat作为子类,分别继承Animal class Animal{ public void shout(){ System.out.println("叫了一声& ...

  8. 什么是DDL,DCL,DML

    1.DCL 数据库控制语言,全称是Data Control Language 关键字类型:grant.remove 2.DDL 数据库定义语言,全称是Data Definition Language ...

  9. 编写规范的javascript

    js代码,前端都会写.但细节决定成败,代码是否优雅.规范,可以看得出一个JScoder的水平来. 曾经多次被项目组长吐槽,并被授予一本秘笈,上面有关于JS编程规范的一些总结. 无奈秘笈不能长借,无奈只 ...

  10. Visual Studio 2013复制项目

    在当前解决方案下复制项目的步骤: 1. 在硬盘存放代码的目录下将整个文件拷贝一份,修改文件夹名字,改成新的项目名称, 然后修改 *.csproj文件,名字必须与新项目名一致. 2. 在解决方案上右键 ...