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 [email protected]
    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

猜你喜欢

转载自blog.csdn.net/kerry2018/article/details/83096523
今日推荐