Persekitaran eksperimen
Mesin maya centos 7.3 yang dipasang secara minima
Konfigurasikan persekitaran asas
1
yum install -y epel-* yum isntall -y nginx vim
2. Wujudkan direktori akar tapak hos mesin maya
mkdir /var/wwwroot mkdir /var/wwwroot/site1 mkdir /var/wwwroot/site2 echo -e "site1" >> /var/wwwroot/site1/index.html echo -e "site2" >> /var/wwwroot/site2/index.html
3. Matikan tembok api centos
setenforce 0 systemctl stop firewalld systemctl disable firewalld
Konfigurasikan hos maya berasaskan port
1 Edit fail konfigurasi nginx
vim /etc/nginx/conf.d/vhosts.conf
Tambah kandungan berikut
server { listen 8081; root /var/wwwroot/site1; index index.html; location / { } } server { listen 8082; root /var/wwwroot/site2; index index.html; location / { } }
3 Mulakan perkhidmatan nginx
systemctl start nginx
http://192.168.204.135:8081/
http://192.168.204.135:8082/
Konfigurasikan hos maya berdasarkan nama domain
1 -edit fail konfigurasi nginxvim /etc/nginx/conf.d/vhosts.conf
server { listen 80; server_name site1.test.com; root /var/wwwroot/site1; index index.html; location / { } } server { listen 80; server_name site2.test.com; root /var/wwwroot/site2; index index.html; location / { } }
systemctl restart nginx
nginx
4. Dalam tingkap Ubah suai fail hosts
edit fail
c:windowssystem32driversetchosts
tambah kandungan berikut (ubah suai mengikut situasi sebenar)
192.168.204.135 site1.test.com
192.168.204.135 site2.test.com
5
http://site1.test.com/
http://site2.test.com/
ifconfig ens33:1 192.168.204.151 ifconfig ens33:2 192.168.204.152
vim /etc/nginx/conf.d/vhosts.conf
server { listen 192.168.204.151:80; root /var/wwwroot/site1; index index.html; location / { } } server { listen 192.168.204.152:80; root /var/wwwroot/site2; index index.html; location / { } }
4 Mulakan semula perkhidmatan
systemctl restart nginx
5. 🎜>
nginx
Atas ialah kandungan terperinci Bagaimana untuk mengkonfigurasi hos maya Nginx pada CentOS. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!