nginx配置多端口多域名访问

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


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

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

然后重起nginx服务器,域名就绑定成功了nginx服务器重起命令:/etc/init.d/nginx restart

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

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

 

二、多端口

在 nginx.conf 中配置两个server即可:

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on; 

    keepalive_timeout  65; 

    gzip  on;

    upstream mylocalhost {
        server 127.0.0.1:8080 max_fails=7 fail_timeout=7s;
    }   
    server {
        listen       81; 
        server_name  localhost;
        location / { 
            root html;
            index index.html index.htm;
            proxy_pass http://mylocalhost;
        }   
    }   
    server {
        listen       80; 
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / { 
            root   html;
            index  index.html index.htm;
            proxy_pass http://mylocalhost;
        }
    }
}

 

转载于:https://my.oschina.net/ososchina/blog/1545845

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值