In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to configure the Nginx virtual host in CentOS 7.3. it is very detailed and has a certain reference value. Interested friends must read it!
Experimental environment
A minimally installed CentOS 7.3virtual machine
Configure the basic environment
1. Install nginx
Yum install-y epel-*yum isntall-y nginx vim
two。 Establish the site root directory of the virtual host
Mkdir / var/wwwrootmkdir / var/wwwroot/site1mkdir / var/wwwroot/site2echo-e "site1" > > / var/wwwroot/site1/index.htmlecho-e "site2" > > / var/wwwroot/site2/index.html
3. Turn off CentOS's firewall
Setenforce 0systemctl stop firewalldsystemctl disable firewalld
Configure a port-based virtual host
1. Edit nginx profile
Vim / etc/nginx/conf.d/vhosts.conf
two。 Add the following
Server {listen 8081; root/ var/wwwroot/site1; index index.html; location / {}} server {listen 8082; root/ var/wwwroot/site2; index index.html; location / {}}
3. Start the nginx service
Systemctl start nginx
4. Visit two sites on the host
Http://192.168.204.135:8081/
Http://192.168.204.135:8082/
Configure a domain name-based virtual host
1. Re-edit the nginx profile
Vim / etc/nginx/conf.d/vhosts.conf
two。 Delete the original content and re-add the following
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 / {}}
3. Restart the nginx service
Systemctl restart nginx
4. Modify the hosts file on Windows
Edit the C:\ Windows\ System32\ drivers\ etc\ hosts file
Add the following (modify it according to the actual situation)
192.168.204.135 site1.test.com
192.168.204.135 site2.test.com
5. Visit two sites on the host
Http://site1.test.com/
Http://site2.test.com/
Configure a virtual host based on IP
1. Add two IP addresses to the virtual machine
Ifconfig ens33:1 192.168.204.151ifconfig ens33:2 192.168.204.152
two。 Re-edit the nginx profile
Vim / etc/nginx/conf.d/vhosts.conf
3. Delete the original content and re-add the following
Server {listen 192.168.204.151 root/ var/wwwroot/site1; index index.html; location / {}} server {listen 192.168.204.152 server 80; root/ var/wwwroot/site2; index index.html; location / {}}
4. Restart the nginx service
Systemctl restart nginx
5. Visit two sites on the host
Http://192.168.204.151/
Http://192.168.204.152/
These are all the contents of the article "how to configure Nginx virtual hosts in CentOS 7.3.Thank you for reading!" Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.