In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Nginx virtual host
Combined with the previous article: manual compilation of NginxNginx virtual host construction process, the concept of virtual host in the previous Apache virtual host building experiment has talked about the relevant knowledge points, the original link: Apache web virtual host
Perform the following configuration operations in combination with the configuration in the previous article (the Nginx service is on)
[root@localhost named] # netstat-natp | grep 80
Tcp 0 0 0.0.0 0 master 80 0.0.0 0. 0. 0 master
Nginx virtual host configuration
1. Domain name resolution configuration (environment preparation)
[root@localhost ~] # yum install-y bind...// omitted part of the content dhclient.x86_64 12 dhclient.x86_64 4.2.5-77.el7.centos dhcp-common.x86_64 12 dhclient.x86_64 4.2.5-77.el7.centos dhcp-libs.x86_64 12 dhclient.x86_64 4.2.5-77.el7 .centos Complete! [root@localhost ~] # vim / etc/named.conf [root@localhost ~] # head-21 / etc/named.conf | tail options {listen-on port 53 {any }; listen-on-v6 port 53 {:: 1;}; directory "/ var/named"; dump-file "/ var/named/data/cache_dump.db"; statistics-file "/ var/named/data/named_stats.txt"; memstatistics-file "/ var/named/data/named_mem_stats.txt"; recursing-file "/ var/named/data/named.recursing" Secroots-file "/ var/named/data/named.secroots"; allow-query {any;}; [root@localhost ~] # vim / etc/named.rfc1912.zones [root@localhost ~] # vim / etc/named.rfc1912.zones [root@localhost ~] # head-34 / etc/named.rfc1912.zones | tail zone "ll.com" IN {type master; file "ll.com.zone"; allow-update {none;};} Zone "cc.com" IN {type master; file "cc.com.zone"; allow-update {none;} [root@localhost ~] # cd / var/named/ [root@localhost named] # lsdata dynamic named.ca named.empty named.localhost named.loopback slaves [root@localhost named] # cp-p named.localhost ll.com.zone [root@localhost named] # vim ll.com.zone [root@localhost named] # cp-p ll.com.zone cc.com.zone [root@localhost named] # cat ll.com.zone $TTL 1D @ IN SOA @ rname.invalid. (0; serial 1D; refresh 1H; retry 1W; expire 3H) Minimum NS @ A 127.0.0.1www IN A 192.168.68.144 [root@localhost named] # cat cc.com.zone $TTL 1D @ IN SOA @ rname.invalid. (0; serial 1D; refresh 1H; retry 1W; expire 3H) Minimum NS @ A 127.0.0.1www IN A 192.168.68.144 [root@localhost named] # systemctl start named [root@localhost named] # systemctl stop firewalld.service [root@localhost named] # setenforce usage: setenforce [Enforcing | Permissive | 1 | 0] [root@localhost named] # setenforce 0
two。 Use the nslookup command on the win10 virtual machine to test for normal parsing
3. Create a site
[root@localhost ~] # mkdir-p / var/www/html/ll [root@localhost ~] # mkdir-p / var/www/html/cc [root@localhost ~] # cd / var/www/html/ [root@localhost html] # lscc ll [root@localhost html] # echo "this is ll test web" > ll/index.html [root@localhost html] # echo "this is cc test web" > cc/index.html [root@localhost html] # ls ll/index.html [root@localhost html] # lscc / index.html4. Service resolution settings based on different domain names [root@localhost html] # cd / usr/local/nginx/conf/ [root@localhost conf] # vim / usr/local/nginx/conf/nginx.conf [root@localhost conf] # sed-n '35p' nginx.conf server {listen 80; server_name www.ll.com; charset utf-8; access_log logs/www.ll.com.access.log Location / {root / var/html/ll; index index.html index.htm;} error_page 500 502 503 504 / 50x.html; location = / 50x.html {root html;}} server {listen 80; server_name www.cc.com; charset utf-8 Access_log logs/www.cc.com.access.log; location / {root / var/html/cc; index index.html index.htm;} error_page 500 502 503 504 / 50x.html; location = / 50x.html {root html }} [root@localhost conf] # nginx-tnginx: the configuration file / usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file / usr/local/nginx/conf/nginx.conf test is successful [root@localhost conf] # service nginx restart
5. Testing of different domain names
Nginx is accessed based on different ports
Continue according to the configuration in step 4 above
[root@localhost conf] # sed-n'35 server_name www.ll.com; charset utf-8; access_log logs/www.ll.com.access.log; location 63p' nginx.conf server {listen 192.168.68.144listen 80; server_name www.ll.com; charset utf-8; access_log logs/www.ll.com.access.log; location / {root / var/www/html/ll; index index.html index.htm } error_page 500 502 503 504 / 50x.htl; location = / 50x.html {root html;}} server {listen 192.168.68.144virtual 8080; server_name www.cc.com; charset utf-8; access_log logs/www.cc8080.com.access.log Location / {root / var/www/html/cc8080; index index.html index.htm;} error_page 500 502 503 504 / 50x.html; location = / 50x.html {root html }} nginx-t [root@localhost conf] # nginx-tnginx: the configuration file / usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file / usr/local/nginx/conf/nginx.conf test is successful [root@localhost conf] # service nginx restart
Detect:
Nginx is accessed based on different IP addresses
Add a network card to select nat mode
Mine is 192.168.68.150
1. Modify the zone data profile
[root@localhost conf] # vim / var/named/cc.com.zone [root@localhost conf] # cat / var/named/cc.com.zone $TTL 1D @ IN SOA @ rname.invalid. (0; serial 1D; refresh 1H; retry 1W; expire 3H) Minimum NS @ A 127.0.0.1www IN A 192.168.68.150 [root@localhost conf] # systemctl restart named
Check to see if the resolution is successful:
two。 Change the configuration file
[root@localhost conf] # vim nginx.conf [root@localhost conf] # sed-n'35 Magi 63p' nginx.conf server {listen 192.168.68.144sed 80; server_name www.ll.com; charset utf-8; access_log logs/www.ll.com.access.log; location / {root / var/www/html/ll; index index.html index.htm } error_page 500 502 503 504 / 50x.htl; location = / 50x.html {root html;}} server {listen 192.168.68.150 root html; 80; server_name www.cc.com; charset utf-8; access_log logs/www.cc.com.access.log Location / {root / var/www/html/cc; index index.html index.htm;} error_page 500 502 503 504 / 50x.html; location = / 50x.html {root html }} [root@localhost conf] # nginx-tnginx: the configuration file / usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file / usr/local/nginx/conf/nginx.conf test is successful [root@localhost conf] # service nginx restart
Check the test:
Summary
This paper is mainly about the relevant configuration of the virtual host of Nginx on the basis of manual compilation and installation of Nginx, corresponding to different domain names, different ports and different ip. What is important is the configuration of Nginx's configuration file, nginx.conf. The configuration of domain name resolution here needs to be skillful.
In the next article, we will introduce the process of building the LNMP architecture.
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.