[root@client1 ~]# cd /etc/yum.repos.d/
[root@client1 yum.repos.d]# vim nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
[root@client1 yum.repos.d]# yum -y install nginx
[root@client1 yum.repos.d]# cd /etc/nginx/conf.d/
[root@client1 conf.d]# vim a.org.conf
server {
server_name www.a.org a.org;
error_log /usr/local/nginx/logs/a.org/error.org error;
access_log /usr/local/nginx/logs/a.org/access.log main;
location / {
root /a.org;
index index.html;
}
}
[root@client1 ~]# mkdir -p /usr/local/nginx/logs/a.org
[root@client1 ~]# mkdir -p /a.org
[root@client1 ~]# echo welcome to nginx > /a.org/index.html
[root@client1 ~]# cd /etc/nginx/conf.d/
[root@client1 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@client1 conf.d]# systemctl start nginx
[root@client1 ~]# ss -antp |grep 80
LISTEN 0 128 *:80 *:* users:(("nginx",pid=1244,fd=8),("nginx",pid=1243,fd=8))
[root@client1 conf.d]# curl 192.168.122.137
welcome to nginx
[root@client1 conf.d]# curl www.a.org
<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx</center>
</body>
</html>
[root@client1 conf.d]# cp a.org.conf b.org.conf
[root@client1 conf.d]# vim b.org.conf
server {
server_name www.b.org b.org;
error_log /usr/local/nginx/logs/b.org/error.org error;
access_log /usr/local/nginx/logs/b.org/access.log main;
location / {
root /b.org;
index index.html;
}
}
[root@client1 conf.d]# mkdir /b.org
[root@client1 conf.d]# mkdir /usr/local/nginx/logs/b.org
[root@client1 conf.d]# vim /b.org/index.html
[root@client1 conf.d]# systemctl stop nginx
[root@client1 conf.d]# systemctl start nginx
nginx部署简单网站(centos7)
最新推荐文章于 2025-04-15 16:56:26 发布