First, simple installation steps structures
0. Check the environment
1. Configure yum source
Use yum List nginx check yum whether a source nginx installation package
# Official online source you need to install epel- *
# Or 251 of adv source (the teacher's yum source)
####################
[base]
name=base
baseurl=http://172.16.105.251/base
enabled=1
gpgcheck=0
[adv]
name=adv
baseurl=http://172.16.105.251/adv
enabled=1
gpgcheck=0
####################
2. install nginx
yum -y install nginx
3. Start Service
systemctl start nginx
systemctl enable nginx
4. Add a Firewall
# Press Service
firewall-cmd --add-service=http
firewall-cmd --add-service=http --permanent
# By Port
netstat -anp |grep nginx
firewall-cmd --add-port=80/tcp
firewall-cmd --add-port=80/tcp --permanent
5. Browser validation
IP
6. Edit Home
/usr/share/nginx/html/index.html
Second, according to port differentiate to build a virtual site
1. Installation Service
yum -y install nginx
2. establish a path
mkdir -p /work/ng1
mkdir -p /work/ng2
echo "1.com" > /work/ng1/index.html
echo "2.com" > /work/ng2/index.html
3. Edit Profile
cd /etc/nginx/conf.d
the ab.conf
###########################
server {
listen 81;
server_name a.com;
location / {
root / Work / NG1; #root can also be written in the location outside
}
}
server {
listen 82;
server_name a.com;
location / {
root /work/ng2 ;
}
}
########################
# Note that each line of the last, if not the {} will need to write ;
4. Troubleshooting
-t nginx # is very important, after writing good idea to check the configuration file
5. Restart Service
systemctl restart nginx
6. Add a firewall port
firewall-cmd --add-port=81/tcp --permanent
firewall-cmd --add-port=82/tcp --permanent
firewall-cmd --reload
7. Verify
curl 192.168.10.100:81
curl 192.168.10.100:82
Third, set up by domain name to distinguish the virtual site
1. Installation Service
yum -y install nginx
2. establish a path
mkdir -p /work/ng1
mkdir -p /work/ng2
echo "1.com" > /work/ng1/index.html
echo "2.com" > /work/ng2/index.html
3. Edit Profile
cd /etc/nginx/conf.d
the ab.conf
###########################
server {
listen 80;
server_name 1.com;
location / {
root /work/ng1 ;
}
}
server {
listen 80;
server_name 2.com;
location / {
root /work/ng2 ;
}
}
########################
# Note that each line of the last, if not the {} will need to write ;
4. Troubleshooting
nginx -t
5. Restart Service
systemctl restart nginx
6. Add a firewall port
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --reload
7. Set the domain name resolved statically
echo "192.168.10.100 1.com" >> /etc/hosts
echo "192.168.10.100 2.com" >> /etc/hosts
8. Verify
curl 1.com
curl 2.com