配置nginx 虚拟主机
可以使用dns 或者在 /etc/hosts中配置
echo "192.168.23.103 www.mynet.com www.benet.com" >> /etc/hosts
mkdir -p /var/www/html/mynet mkdir -p /var/www/html/benet echo "this is mynet.com" > /var/www/html/mynet/index.html echo "this is benet.com" > /var/www/html/benet/index.html
vim /usr/local/nginx/conf/nginx.conf server { listen 80; server_name www.mynet.com; #设置域名 www.mynet.com charset utf-8; #设置网页字符集 access_log logs/www.mynet.access.log ; #设置www.mynet.com网站的访问日志 location / { root /var/www/html/mynet; #设置网页文件根目录 index index.html index.htm; #设置首页文件 } .... } server { listen 80; server_name www.benet.com; #设置域名为 www.benet.com charset utf-8; access_log logs/www.benet.access.log ;#设置www.benet.com 访问日志 location / { root /var/www/html/benet; #设置网页文件根目录 index index.html index.htm; ........ } }
nginx -t nginx -s reload curl http://www.mynet.com curl http://www.benet.com
ifconfig ens33:0 192.168.23.130 netmask 255.255.255.0
vim /usr/local/nginx/conf/nginx.conf server { listen 192.168.23.130:80; #设置监听地址为 192.168.23.130:80 server_name localhost; charset utf-8; location / { root html; index index.html index.htm; } } server { listen 192.168.23.103:80; #设置监听地址为 192.168.23.103:80 server_name localhost; charset utf-8; location / { root html; index index.html index.htm; } }
echo "hello" > /usr/local/nginx/html/index.html nginx -t nginx -s reload netstat -natp | grep :80
curl http://192.168.23.103 curl http://192.168.23.130
vim /usr/local/nginx/conf/nginx.conf server { listen 192.168.23.103:80; #设置监听地址为 192.168.23.103:80 server_name localhost; charset utf-8; location / { root html; index index.html index.htm; } } server { listen 192.168.23.103:80; #设置监听地址为 192.168.23.103:8080 server_name localhost; charset utf-8; location / { root html; index index.html index.htm; } }
nginx -t nginx -s reload netstat -natp | grep nginx
curl http://192.168.23.103:80 curl http://192.168.23.103:8080