zoukankan      html  css  js  c++  java
  • nginx 多域名配置 (nginx如何绑定多个域名)

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

         一、每个域名一个文件的写法

        首先打开nginx域名配置文件存放目录:/usr/local/nginx/conf/servers ,如要绑定域名www.web126.com 则在此目录建一个文件:www.web126.com.conf 然后在此文件中写规则,如:

    server 

    listen       80; 
    server_name www.web126.com;             #绑定域名 
    index index.htm index.html index.php;      #默认文件 
    root /home/www/web126.com;               #网站根目录
    include location.conf;                            #调用其他规则,也可去除
    }

    然后重起nginx服务器,域名就绑定成功了

    nginx服务器重起命令:/etc/init.d/nginx restart

        二、一个文件多个域名的写法

        一个文件添加多个域名的规则也是一样,只要把上面单个域名重复写下来就ok了,如:

    server 

    listen       80; 
    server_name www.web126.com;             #绑定域名 
    index index.htm index.html index.php;      #默认文件 
    root /home/www/web126.com;               #网站根目录
    include location.conf;                            #调用其他规则,也可去除
    }

    server 

    listen       80; 
    server_name msn.web126.com;             #绑定域名 
    index index.htm index.html index.php;      #默认文件 
    root /home/www/msn.web126.com;        #网站根目录
    include location.conf;                            #调用其他规则,也可去除
    }

        三、不带www的域名加301跳转

        如果不带www的域名要加301跳转,那也是和绑定域名一样,先绑定不带www的域名,只是不用写网站目录,而是进行301跳转,如:

    server
    {
    listen 80;
    server_name web126.com;
    rewrite ^/(.*) http://www.web126.com/$1 permanent;
    }

        四、添加404网页

        添加404网页,都可又直接在里面添加,如:

    server 

    listen       80; 
    server_name www.web126.com;             #绑定域名 
    index index.htm index.html index.php;      #默认文件 
    root /home/www/web126.com;               #网站根目录
    include location.conf;                            #调用其他规则,也可去除
    error_page 404  /404.html; 
    }

        学会上面四种规则方法,基本就可以自己独立解决nginx 多域名配置问题了

    From: http://www.web126.com/JiShuWenDang/306.htm

  • 相关阅读:
    CentOS 6.6 升级GCC G++ (当前最新版本为v6.1.0) (完整)
    telnet: Unable to connect to remote host: Connection refused
    bash: telnet: command not found (Linux安装telnet)
    telnet: Unable to connect to remote host: No route to host
    IP地址转换函数
    Linux 网络通信 API详解【转载】
    高效算法求解数独
    Java创建List、Map等集合对象的同时进行赋值操作
    根据先序遍历和中序遍历建立二叉树
    继承内部类时使用外部类对象.super()调用内部类的构造方法
  • 原文地址:https://www.cnblogs.com/imxiu/p/3296172.html
Copyright © 2011-2022 走看看