echo "192.168.229.60 www.ly.com www.weq.com" >> /etc/hosts
mkdir -p /var/www/html/ly/ mkdir -p /var/www/html/weq/ echo "<h1>www.ly.com</h1>" > /var/www/html/ly/index.html echo "<h1>www.weq.com</h1>" > /var/www/html/weq/index.html
vim /usr/local/nginx/conf/nginx.conf
server {
listen 80;
server_name www.ly.com; #设置域名
charset utf-8; #设置网页字符集
access_log logs/ly.com.access.log; #设置日志名
location / {
root /var/www/html/ly; #设置www.ly.com的工作目录
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 80;
server_name www.weq.com; #设置域名
charset utf-8; #设置网页字符集
access_log logs/weq.com.access.log; #设置日志名
location / {
root /var/www/html/weq; #设置www.weq.com的工作目录
index index.html index.htm;
}
systemctl restart nginx
浏览器访问http://www.ly.com
浏览器访问http://www.weq.com
[root@192 ~]# vim /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.229.60 www.ly.com www.weq.com
[root@192 ~]# mkdir -p /var/www/html/ly [root@192 ~]# mkdir -p /var/www/html/weq [root@192 ~]# cd /var/www/html/ [root@192 html]# ls ly weq [root@192 html]# echo "<h1>This is www.ly.com web!</h1>" > /var/www/html/ly/index.html -bash: !: event not found [root@192 html]# echo "<h1>This is www.ly.com web!</h1>" > /var/www/html/ly/index.html [root@192 html]# echo "<h1>This is www.weq.com web!</h1>" > /var/www/html/weq/index.html
[root@cm html]# cd /usr/local/nginx/conf/ [root@cm conf]# ls fastcgi.conf fastcgi_params.default mime.types nginx.conf.bak scgi_params.default win-utf fastcgi.conf.default koi-utf mime.types.default nginx.conf.default uwsgi_params fastcgi_params koi-win nginx.conf scgi_params uwsgi_params.default [root@cm conf]# cp nginx.conf.bak nginx.conf cp:是否覆盖"nginx.conf"? yes
[root@cm conf]# vim nginx.conf
server {
listen 80;
server_name www.ly.com;
charset utf-8;
access_log logs/ly.com.access.log;
location / {
root /var/www/html/ly;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 80;
server_name www.weq.com;
charset utf-8;
access_log logs/weq.com.access.log;
location / {
root /var/www/html/weq;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
[root@cm 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@cm conf]# systemctl restart nginx
ifconfig ens33:1 192.168.229.88/24 vim /usr/local/nginx/conf/nginx.conf
server {
listen 192.168.229.60:80; #修改监听的为ip
server_name www.ly.com;
charset utf-8;
access_log logs/ly.com.access.log;
location / {
root /var/www/html/ly;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 192.168.229.88:80; #修改监听的为ip
server_name www.weq.com;
charset utf-8;
access_log logs/weq.com.access.log;
location / {
root /var/www/html/weq;
index index.html index.htm;
}
nginx -t systemctl restart nginx
浏览器访问http://192.168.229.60:80
浏览器访问http://192.168.229.88:80
[root@cm conf]# ifconfig ens33:1 192.168.229.88/24
[root@cm conf]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.229.60 netmask 255.255.255.0 broadcast 192.168.229.255
inet6 fe80::20c:29ff:fe4a:778d prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:4a:77:8d txqueuelen 1000 (Ethernet)
RX packets 160977 bytes 233171378 (222.3 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 21671 bytes 1543265 (1.4 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens33:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.229.88 netmask 255.255.255.0 broadcast 192.168.229.255
ether 00:0c:29:4a:77:8d txqueuelen 1000 (Ethernet)
[root@cm conf]# vim nginx.conf [root@cm 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@cm conf]# systemctl restart nginx
vim /usr.local/nginx/conf/nginx.conf
server {
listen 192.168.229.60:8080; #修改监听的为ip
server_name www.ly.com;
charset utf-8;
access_log logs/ly.com.access.log;
location / {
root /var/www/html/ly;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 192.168.229.88:888; #修改监听的为ip
server_name www.weq.com;
charset utf-8;
access_log logs/weq.com.access.log;
location / {
root /var/www/html/weq;
index index.html index.htm;
}
nginx -t systemctl restart nginx.service
浏览器访问http://192.168.229.60:8080
浏览器访问http://192.168.229:88:888
[root@cm conf]# vim nginx.conf [root@cm 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@cm conf]# systemctl restart nginx
Nginx网站服务——Nginx虚拟主机(基于域名、IP、端口)附带超详细实验步骤
原文:https://www.cnblogs.com/weq0805/p/15127303.html