apache和nginx虚拟主机的配置

apache虚拟主机配置:

[[root@zookeeper conf.d]# mkdir /webroot/web1   

root@zookeeper conf.d]# mkdir -p /var/log/httpd/web1/      //准备网站根目录和日志存放目录(日志目录可不写)

[root@zookeeper conf.d]# echo this is web1 html> /webroot/web1/index.html

[root@zookeeper html]# cd /etc/httpd/conf.d

[root@zookeeper conf.d]# cat kailey.conf
<VirtualHost 192.168.122.224:80>     //如果监听端口更改了,需要在/etc/httpd/conf/httpd.conf 中配置listen 端口;
    ServerAdmin alice@163.com
    ServerName www.kailey.com
    ServerAlias kailey.com
    DocumentRoot /webroot/web1     后面要和这个一致
    ErrorLog /var/log/httpd/web1/error_log
    CustomLog /var/log/httpd/web1/access_log combined
</VirtualHost>
<Directory "/webroot/web1">                       //网页所在位置
    AllowOverride none
    <RequireAll>
        Require not ip 192.168.122.29
        Require all granted
    </RequireAll>
</Directory>

[root@zookeeper conf.d]# httpd -t
Syntax OK

[root@physical ~]# cat /etc/hosts                                 //在本地主机中做解析
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.122.224 www.kailey.com kailey.com              

[root@zookeeper conf.d]# systemctl restart httpd

[root@physical ~]# elinks --dump www.kailey.com       //物理机做测试访问域名
   this is web1 html

 

nginx虚拟主机配置:

[root@master1 conf.d]# mkdir -p /webroot/a

[root@master1 conf.d]# mkdir -p /var/log/nginx/a

[root@master1 conf.d]# echo nginx a.org > /webroot/a/index.html

[root@master1 ~]# cd /etc/nginx/conf.d/
[root@master1 conf.d]# cat a.org.conf
server{
   listen 80;                                  //如果更改端口只需要再这里跟该端口就行
   server_name www.a.org a.org;

   error_log /var/log/nginx/a/err.log error;
   access_log /var/log/nginx/a/access.log main;

   location / {
    root /webroot/a;
    index index.html index.htm;
   }
}   

[root@master1 conf.d]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

[root@master1 conf.d]# nginx -s reload

[root@physical ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.122.13 www.a.org a.org

[root@physical ~]# elinks --dump www.a.org
   nginx a.org

 

 

 

 

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值