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 > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
In this article, the editor introduces in detail "how to configure the Nginx virtual host by CentOS7.3". The content is detailed, the steps are clear, and the details are handled properly. I hope that this article "how to configure the Nginx virtual host by CentOS7.3" can help you solve your doubts.
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/
After reading this, the article "how to configure Nginx virtual hosts with CentOS7.3" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, 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.