nginx domain name configuration virtual host

Posted by erwt on Fri, 01 Nov 2019 20:51:28 +0100

A domain name, corresponding to an IP address
Through DNS domain name resolution server, domain name can be resolved to IP address

Here
Specify the IP address of the domain name by modifying the host file

host hijacking
In the host file, configure the domain name and IP address. When accessing the domain name,
Because the IP address corresponding to the domain name already exists in the host file
Therefore, it is no longer necessary to access the DNS server for resolution and directly access the corresponding IP address

Location of the host file
C:\Windows\System32\drivers\etc

Nginx profile comment:

 [root@localhost conf]# vim nginx.conf

worker_processes  1;    #Number of worker processes
events {                #Start of event block
worker_connections  1024;            #Maximum number of connections supported per worker process
}                       #End of event block
http {                  #Start of HTTP block
include       mime.types;                #Nginx supports media type library files
default_type  application/octet-stream;    #Default media type
sendfile        on;                        #Turn on high-speed transmission mode
keepalive_timeout  65;                     #connection timed out
server {                                    #Start of the first server block
    listen       80;                        #The port that provides services. The default is 80.
    server_name   www.nautilus.org ;                 #Domain name host providing services
    location / {                            #The beginning of the first location block
        root   html/www;                        #The root directory of the site, equivalent to the installation directory of Nginx
        index  index.html index.htm;        #Default homepage file, multiple separated by spaces
    }                                        #End of first location block
    error_page   500 502 503 504  /50x.html;    #When the corresponding http status code appears, use 50x.html to respond to the customer
    location = /50x.html {                    #Start of location block, visit 50x.html
        root   html;                            #Specify the corresponding site directory as html
    }
}
}                                                   #End of HTTP block

Operation steps

[root@localhost nginx]# ls
client_body_temp  fastcgi_temp  logs        sbin       uwsgi_temp
conf              html          proxy_temp  scgi_temp
[root@localhost nginx]# cd html
[root@localhost html]#
[root@localhost html]# mkdir www    
[root@localhost html]#      
[root@localhost html]# cd www
[root@localhost www]# ls
index.html
[root@localhost www]# vim index.html
   hello  localhost

[root@localhost nginx]# vim /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

172.31.1.32     www.nautilus.org

Visit the website:

        www.nautilus.org

Nginx configuration is based on multiple domain names

    server {
    listen       80;
    server_name  www.nautilus.org;
    location / {
        root   html/www;
        index  index.html index.htm;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}

 server {
    listen       80;
    server_name  bbs.nautilus.org;
    location / {
        root   html/bss;
        index  index.html index.htm;
    }
}

server {
    listen       80;
    server_name  blog.nautilus.org;
    location / {
        root   html/blog;
        index  index.html index.html;
    }

}

[root@localhost nginx]# cd html
[root@localhost html]#
[root@localhost html]# mkdir bbs    
[root@localhost html]#      
[root@localhost html]# cd bbs
[root@localhost bbs]# ls
index.html
[root@localhost bbs]# vim index.html
   hello  bbs
[root@localhost html]# mkdir blog   
[root@localhost html]#      
[root@localhost html]# cd blog
[root@localhost blog]# ls
index.html
[root@localhost blog]# vim index.html
   hello  blog

  [root@localhost html]# ls
50x.html  bbs  blog  index.html  www

[root@localhost nginx]# vim /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

172.31.1.32     www.nautilus.org
172.31.1.32     bbs.nautilus.org
172.31.1.32     blog.nautilus.org

Visit the website:

    www.nautilus.org
    bbs.nautilus.org
    blog.nautilus.org

Topics: Web Server Nginx vim DNS Windows