标签:linux企业常用服务---部署nginx虚拟主机 一个ip地址多个域名
部署前准备:
光盘配置本地yum源,修改yum配置文件
防火墙和selinux不做设置,关掉
IP地址设置为192.168.100.222
nginx已安装完成
1.安装安装并配置dns:
安装dns:
[root@www ~]# yum install bind-utils bind bind-chroot
配置:
[root@www ~]# cd /var/named/chroot/etc/
配置主文件:
[root@www etc]# pwd
/var/named/chroot/etc
[root@www etc]# cat named.conf
options {
directory "/var/named";
};
zone "linuxfan.cn" IN {
type master;
file "linuxfan.cn.zone";
};
zone "linuxren.cn" IN {
type master;
file "linuxren.cn.zone";
};
[root@www etc]# chown named named.conf
[root@www etc]# named-checkconf named.conf ##检测语法
配置区域文件:
[root@www named]# cat linuxren.cn.zone
$TTL 86400
@ SOA linuxren.cn. admin.linuxren.cn. (
20160101
4H
30M
12H
1D
)
@ IN NS ns.linuxren.cn.
ns IN A 192.168.100.222
@ IN A 192.168.100.222
www IN A 192.168.100.222
[root@www named]# cat linuxfan.cn.zone
$TTL 86400
@ SOA linuxfan.cn. admin.linuxfan.cn. (
20131015
4H
30M
12H
1D
)
@ IN NS ns.linuxfan.cn.
ns IN A 192.168.100.222
@ IN A 192.168.100.222
www IN A 192.168.100.222
[root@www named]# pwd
/var/named/chroot/var/named
[root@www named]#
[root@www named]# named-checkzone linuxfan.cn.zone linuxren.cn.zone
zone linuxfan.cn.zone/IN: loaded serial 20131015
OK
[root@www named]# chown named:named linux* ../../etc/named.conf
2.部署nginx虚拟主机:
[root@www ~]# cd /usr/local/nginx/html/
[root@www html]# ls
50x.html index.html
[root@www html]# mkdir linuxfan
[root@www html]# mkdir linuxren
[root@www html]# echo linuxfan.cn >linuxfan/index.html
[root@www html]# echo linuxren.cn >linuxren/index.html
[root@www html]# pwd
/usr/local/nginx/html
[root@www html]#
[root@www html]# vi /usr/local/nginx/conf/nginx.conf
worker_processes 1;
events {
use epoll;
worker_connections 4096;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main ‘$remote_addr -$remote_user [$time_local] "$request"‘
‘$status $body_bytes_sent "$http_referer" ‘
‘"$http_user_agent" "$http_x_forwarded_for" ‘;
access_log logs/access.log main;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name www.linuxfan.cn;
charset utf-8;
access_log logs/linuxfan.access.log main;
location / {
root /usr/local/nginx/html/linuxfan;
index index.html index.php;
}
}
server {
listen 80;
server_name www.linuxren.cn;
charset utf-8;
access_log logs/linuxren.access.log main;
location / {
root /usr/local/nginx/html/linuxren;
index index.html index.php;
}
}
}
[root@www conf]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@www conf]# /etc/init.d/nginx restart
nginx is stopping!!
nginx is starting!!
访问测试:
[root@www conf]# elinks --dump http://www.linuxren.cn
linuxren.cn
[root@www conf]# elinks --dump http://www.linuxfan.cn
linuxfan.cn
最终实现不同的域名访问到一个ip地址
本文出自 “LP-linux” 博客,请务必保留此出处http://linuxlp.blog.51cto.com/11463376/1773554
标签:linux企业常用服务---部署nginx虚拟主机 一个ip地址多个域名
原文地址:http://linuxlp.blog.51cto.com/11463376/1773554