Cloud computing operation and maintenance learning---some common module functions in Nginx service

Use Nginx service to build multiple websites on one virtual host

  1. Create multiple host configuration files in the "/etc/nginx/conf.d/" directory (a server represents a website)
    Insert picture description here
    Insert picture description here
    Insert picture description here
  2. Create the site directory and the home page file in the site directory; here I use the default site directory "/usr/share/nginx/html" and the default home page file "index.html", you can also modify it at will.
    Insert picture description here
  3. Write "Windows/System32/drivers/etc/hosts" parsing file in Windows host
    Insert picture description here
  4. Use the browser in Windows for access test
    Insert picture description here
    Insert picture description here

How to access the website

  • Access based on the domain name has been mentioned above, so I won’t repeat it.
  • Access based on address. (Only use the specified address to access)
    Insert picture description here
  • Access based on port.
    Insert picture description here
    Insert picture description here

Web page to access the principle
Insert picture description here
TIPS: When direct access "10.0.0.7" through the browser, if the monitor is not set, the default sort is open at the top of the homepage. Because the browser finds the server "10.0.0.7", it visits port 80. At this time, the Nginx main configuration file "/etc/nginx/nginx.comf" will load all the extended configuration files of "/etc/nginx/conf.d", and because there is no specific domain name matching, it will follow the order of loading The home page file of the first website is returned to the client.

Website security access configuration

  • Control based on the address the user visits. Need to use nginxf access module: "ngx_http_access_module"; the figure below is some configuration instructions of the "ngx_http_access_module" module I intercepted from the Nginx official website:

Insert picture description here

Actual operation:
Insert picture description here
Insert picture description here
Access "blog.cxsnb.com/blog" on the shell command line:
Insert picture description here
TIPS: The information outside the location is the global configuration information; the information inside the location is the local information.

  • Authentication according to user access; the module that needs to be used is "ngx_http_auth_basic_module"; the figure below is the configuration instructions of some "ngx_http_auth_basic_module" authentication modules that I intercepted from the Nginx official website:
    Insert picture description here
    actual operation:
    first step: writing website extension configuration file
    Insert picture description here
    second Department: Create a password file (the information in the password file must be in cipher text)
    Insert picture description hereInsert picture description here
    Step 3: Test
    Insert picture description here
    TIPS: The initial permission of the password file "/etc/nginx/password/htpasswd" is 644, which is very insecure. You can change the permissions of the password file to 600 so that other users cannot get the password. But simply modify the permissions of the password file, so that when you use the browser to visit the website, it will report a "500" error. Let's explain the principle through a picture.
    Insert picture description here
    Insert picture description here

Guess you like

Origin blog.csdn.net/cxs_123/article/details/109381200