码迷,mamicode.com
首页 > 其他好文 > 详细

Nginx虚拟主机

时间:2018-06-12 14:46:01      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:需要   mime   页面   processes   .com   event   平滑   list   pytho   

五、虚拟主机

1、基于域名

编辑nginx.conf

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  www.hello.com;
        location / {
            root   html/www;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

 创建域名对应的站点目录及文件

#创建目录
mkdir /appliction/nginx/html/www -p
#创建文件
echo "http://www.hello.com" > /appliction/nginx/html/www/index.htm

 检查修改过的nginx配置文件语法是否正确

#执行
/appliction/nginx/sbin/nginx -t

#返回信息
nginx: the configuration file /appliction/nginx-1.14.0//conf/nginx.conf syntax is ok
nginx: configuration file /appliction/nginx-1.14.0//conf/nginx.conf test is successful


#没有问题重启nginx(reload平滑重启)
/appliction/nginx/sbin/nginx -s reload

#检查nginx启动是否正常
ps -ef|grep nginx

#检查端口
netstat -lnt|grep 80

##客户端访问需要在hosts文件内做解析

 

添加多个虚拟主机

#只需要配置多个server,和对应的页面文件路径

worker_processes  1;
events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  www.hello.com;
        location / {
            root   html/hello;
            index  index.html index.htm;
        }
    }


    server {
        listen       80;
        server_name  www.world.com;
        location / {
            root   html/world;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;

        }
    }
}

 

创建对应的文件和目录

mkdir /appliction/nginx/html/hello -p

echo "http://www.hello.com" > /appliction/nginx/html/hello/index.htm

mkdir //appliction/nginx/html/world -p

echo "http://www.world.com" > /appliction/nginx/html/world/index.htm

/appliction/nginx/sbin/nginx -s reload

 

Nginx虚拟主机

标签:需要   mime   页面   processes   .com   event   平滑   list   pytho   

原文地址:https://www.cnblogs.com/hulue/p/9172782.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!