This is the fifth day of my participation in the November Gwen Challenge. Check out the details: The last Gwen Challenge 2021

What is local domain name mapping

In front of the time we explained the purchase of an online domain name, and after the record. What if we want to continue with the course during the filing period, or can we configure a local domain name?

Ok, as long as we know the process of domain name resolution, it will first resolve a host from the local computer, if there is a mapping of the corresponding domain name IP, it will use our local first. If we access 127.0.0.1 through a browser, localhost is the same as accessing 127.0.0.1.

1. Configure local domain name mapping for Mac

The following figure shows the mapping between domain names and IP addresses in the Host file of the Mac operating system

192.168.159.137 aabbcc.com will do. If the browser accesses aabbcc.com, it will be mapped to 192.168.159.137

cd /private/etcsudo vim hosts
Copy the code

2. Window Configure the local domain name mapping

  • First find the host file: C:\Windows\System32\drivers\etc
  • Open the host file
# Copyright (c) 1993-2009 Microsoft Corp. ## This is a sample HOSTS file used by Microsoft TCP/IP for Windows. ## This file contains the mappings of IP addresses to host names. Each # entry should be kept on an individual line. The IP address should # be placed in the first column followed by the corresponding host name. # The IP address and the host name should be separated by at least one # space.## Additionally, comments (such as these) may be inserted on individual # lines or following the machine name denoted by a '#' symbol. ##  For example: # rhino.acme.com # source server # rhino.acme.com # x client host # localhost name resolution is Handled within DNS itself.com # 127.0.0.1 localhost # ::1Copy the code
  • 192.168.159.137 aabbccdd.com = 192.168.159.137 aabbccdd.com
  • Ping aabbccdd.com and press enter to see the IP address from your input, 127.0.0.1

Nginx directory files

Once we have Nginx installed, we need to go inside and take a look at several common folders and what each common file does.

  • Source code compiled after installation, default directory
/ usr/local/nginx.Copy the code
  • Directory and configuration file introduction
Conf # The main default configuration file nginx.conf.default # Default template HTML # This is the default site directory for nginx when compiling the installation Logs # nginx default log path Log #nginx process ID access.log #nginx access log sbin #nginx command directory nginx # start commandCopy the code
  • There are also some common Nginx operation commands
/nginx -s reload Load the default configuration file. / nginx - c/usr/local/nginx/conf/nginx. Start the conf # specify a configuration file. / nginx - # # s stop stop closing process, Nginx have master the process and the worker process, close the master can ps - ef | grep "nginx" kill 9 PIDCopy the code

Nginx core configuration file analysis

Nginx has a lot of configuration files, so we divide it into global configuration, virtual host configuration and path mapping.

The following configuration file is a copy of the configuration file with a lot of comments.

As long as there is no # comment, Nginx side of the configuration, we will learn as we use.

Each configuration item consists of two parts: a configuration directive and an instruction parameter. User group worker_processes 1; # #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; Nginx supports select, poll, kqueue, epoll, etc. # epoll is used on Linux while Kqueue is used on BSD. For Linux, epoll mode is preferred. # define the maximum number of connections per Nginx process, as a server: Worker_connections * worker_processes, # As a reverse proxy, the maximum number of concurrent requests should be worker_connections * worker_processes/2. Worker_connections 1024 worker_connections 1024 worker_connections 1024 } http { include mime.types; default_type application/octet-stream; $remote_addr - $remote_user [$time_local] "$request" '# '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; # Whether to enable efficient transfer mode on On off SendFile on; Tcp_nopush on; #keepalive_timeout 0; Keepalive_timeout 65; keepalive_timeout 65; #gzip on; Server {listen 80; Server_name localhost; #charset koi8-r; #charset koi8-r; #access_log logs/host.access.log main; / {root HTML; Index.html index.htm; } #error_page 404/404.html; Redirect Server error pages to the static page /50x.html redirect Server error pages to the static page /50x.html Error_page 500 502 503 504/50x.html; location = /50x.html { root html; }} # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; Server {# listen 443 SSL; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:! aNULL:! MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # #}}}Copy the code

Inside an HTTP node, you can configure many servers, each server is a virtual host, you can configure a separate domain name mapping.

server { listen 80; Server_name aabbcc.com; {root /usr/local/nginx/ HTML; index xdclass.html; } } server { listen 80; server_name aabbccdd.com; location / { root html; index xdclass.html index.htm; }}Copy the code