Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Domain name, port, IP of Nginx virtual host

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

If you want the nginx source code package, please send me the domain name of the Nginx virtual host.

[root@localhost ~] # yum install bind-y

Configure DNS main configuration file [root@localhost ~] # vim / etc/named.conf 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;}; configuration area profile [root@localhost ~] # vim / etc/named.rfc1912.zones zone "cwq.com" IN {type master File "cwq.com.zone"; allow-update {none;};} zone "kgc.com" IN {type master; file "kgc.com.zone"; allow-update {none;};} Zone "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0. Configure the zone data configuration file [root@localhost ~] # cd / var/named/ [root@localhost named] # cp-p named.localhost cwq.com.zone [root@localhost named] # vim cwq.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.136.162 [root@localhost named] # cp-p cwq.com.zone kgc.com.zone start the DNS service [root@localhost named] # systemctl start named [root@localhost named] # systemctl stop firewalld.service [root@localhost named] # setenforce 0 to test whether the domain name can be resolved

Install the nginx environment package [root@localhost named] # yum install gcc gcc-c++ pcre-devel zlib-devel-y [root@localhost named] # mkdir / abc [root@localhost named] # mount.cifs / / 192.168.100.23/LNMP / abcPassword for root@//192.168.100.23/LNMP: [root@localhost named] # cd / abc/ [root@localhost abc] # lsmysql-boost-5.7.20.tar.gz nginx-1.12.2.tar.gz php- 7.1.20.tar.gznginx-1.12.0.tar.gz php-7.1.10.tar.bz2 [root@localhost abc] # tar zxvf nginx-1.12.2.tar.gz-C / opt/ compilation and installation [root@localhost abc] # cd / opt/ [root@localhost opt] # cd nginx-1.12.2/ [root@localhost nginx-1.12.2] # useradd-M-s / sbin/nologin nginx # create programmatic users to manage -M has no home directory -s does not log in to the local console. / configure\-- prefix=/usr/local/nginx\ # specify path-- user=nginx\ # specify user-- group=nginx\ # specify group-- with-http_stub_status_module # status statistics module [root@localhost nginx-1.12.2] # make [root@localhost nginx-1.12.2] # make install when it compiles, we open another terminal to create the site web page [root] @ localhost ~] # mkdir-p / var/www/html/cwq [root@localhost ~] # mkdir-p / var/www/html/kgc [root@localhost ~] # cd / var/www/html/ [root@localhost html] # lscwq kgc [root@localhost html] # echo "this is cwq web" > cwq/index.html [root@localhost html] # echo "this is kgc web" > kgc/index.html [root@localhost html] # lscwq / index.html [root@localhost html] # ls kgc/index.html Test syntax [root@localhost nginx-1.12.2] # ln-s / usr/local/nginx/sbin/nginx / usr/local/sbin/ [root@localhost nginx-1.12.2] # 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 write nginx script in the system startup script to facilitate service manager management [root@localhost nginx-1.12 .2] # cd / etc/init.d/ [root@localhost init.d] # vim nginx #! / bin/bash#chkconfig:-99 20 # comment Information # description: Nginx Service Control ScriptPROG= "/ usr/local/nginx/sbin/nginx" # this variable Point to my command file PIDF= "/ usr/local/nginx/logs/nginx.pid" # this variable, and point to the nginx process number case "$1" in start) $PROG ; stop) kill-s QUIT $(cat $PIDF);; restart) $0 stop $0 start;; reload) kill-s HUP $(cat $PIDF) *) echo "Usage: $0 {start | stop | restart | reload}" exit 1esacexit 0 [root@localhost init.d] # chmod + x nginx # add execution permission [root@localhost init.d] # chkconfig-- add nginx # add nginx [root@localhost init.d] # service nginx start [root@localhost init.d] # Netstat-ntap | grep nginx # check whether the nginx port has been provided tcp 00 0.0.0.0 grep nginx 80 0.0.0.0 tcp * LISTEN 42982/nginx: master and then test it with win10 What we need is different domain names to visit different web pages.

Edit the nginx configuration file [root@localhost init.d] # cd / usr/local/nginx/conf/ [root@localhost conf] # vim nginx.conf#sever area to delete all other redundant server {listen 80; 33 server_name www.cwq.com; # domain name 34 charset utf-8; # identify Chinese character set 35 access_log logs/www.cwq.com.access.log # Domain name log file 36 location / {37 root / var/www/html/cwq; # designated site 38 index index.html index.htm; 39} 40 error_page 500502 503 504 / 50x.htl; 41 location = / 50x.html {42 root html 43} 44} 45 46 47 server {48 listen 80; 49 server_name www.kgc.com; 50 charset utf-8; 51 access_log logs/www.kgc.com.access.log; 52 location / {53 root / var/www/html/kgc; 54 index index.html index.htm 55} 56 error_page 500 502 503 504 / 50x.html; 57 location = / 50x.html {58 root html 59} 60} 61 # another virtual host using mix of IP-, name-, and port-based configuration # extra content is deleted to this place to check the grammar, restart the service [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 to win10 to test again

Based on the port of Nginx virtual host, write a web page for port 8080 [root@localhost conf] # cd / var/www/html/ [root@localhost html] # mkdir kgc8080 [root@localhost html] # echo "this is kgc8080 web" > kgc8080/index.html configuration nginx file [root@localhost html] # cd / usr/local/nginx/conf/# first comment out our previous cwq domain name, 31 44 s / ^ / # / g, otherwise 31 # server {# listen 80 will conflict with the following address 33 # server_name www.cwq.com; 34 # charset utf-8; 35 # access_log logs/www.cwq.com.access.log; 36 # location / {37 # root / var/www/html/cwq; 38 # index index.html index.htm; 39 #} 40 # error_page 500 502 503 504 / 50x.html 41 # location = / 50x.html {42 # root html; 43 #} 44 #} 46 server {47 listen 192.168.136.162 listen 80; 48 server_name www.kgc.com; 49 charset utf-8; 50 access_log logs/www.kgc.com.access.log 51 location / {52 root / var/www/html/kgc; 53 index index.html index.htm; 54} 55 error_page 500 502 503 504 / 50x.html; 56 location = / 50x.html {57 root html; 58} 59} 60 61 server {62 listen 192.168.136.162 8080 63 server_name www.kgc.com; 64 charset utf-8; 65 access_log logs/www.kgc8080.com.access.log; # Log files 66 location / {67 root / var/www/html/kgc8080; # sites with different ports 68 index index.html index.htm; 69} 70 error_page 500 502 503 504 / 50x.html 71 location = / 50x.html {72 root html 73} 74} check syntax and restart service Check whether two ports have been provided [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 [root@localhost conf] # netstat-ntap | grep nginxtcp 0 0192.168.136.162Vera 8080 0.0.0.0 * LISTEN 43616/nginx: master tcp 0 192.168.136.162 LISTEN 43616/nginx 80 0.0.0.0 LISTEN 43616/nginx: go to win10 for a test

This is the URL of my second network card, the Nginx virtual host, based on the IP address, let's add a network card to the server first.

This is the URL of my second network card ens36: flags=4163 mtu 1500 inet 192.168.136.171 netmask 255.255.255.0 broadcast 192.168.136.255kgc area data configuration file change the address [root@localhost ~] # cd / var/named/ [root@localhost named] # vim kgc.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.136.171 [root@localhost named] # systemctl restart named tests whether the domain name can be resolved successfully with win10

Configure the nginx configuration file [root@localhost named] # cd / usr/local/nginx/conf/ [root@localhost conf] # vim nginx.conf# to comment out the previous port, 61 # server {62 # listen 192.168.136.162 80; 63 # server_name www.kgc.com; 64 # charset utf-8; 65 # access_log logs/www.kgc8080.com.access.log 66 # location / {67 # root / var/www/html/kgc8080; 68 # index index.html index.htm; 69 #} 70 # error_page 500 502 503 504 / 50x.html; 71 # location = / 50x.html {72 # root html 73 #} 74 #} # remove the previous comments, 31 s/#//g31 server 44 s/#//g31 server {listen 192.168.136.162 access_log logs/www.cwq.com.access.log; 80; 33 server_name www.cwq.com; 34 charset utf-8; 35 access_log logs/www.cwq.com.access.log; 36 location / {37 root / var/www/html/cwq 38 index index.html index.htm; 39} 40 error_page 500 502 503 504 / 50x.htl; 41 location = / 50x.html {42 root html; 43} 44} # the regional listening address of the kgc is replaced by the address of the second network card 47 listen 192.168.136.171 Check the syntax and restart the service [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 and then go to win10 to test whether different URLs (domain names) get the same web page.

That's all we have. Thank you for watching.

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report