This is the 16th day of my participation in the August More Text Challenge. For details, see:August is more challenging

In the last article, I wrote about the Nginx infrastructure. The Nginx development process may not require much architecture-related knowledge, but some knowledge of the Nginx infrastructure will help us understand the Nginx configuration at a deeper level.

This article brings you the basic Nginx configuration, let you understand the basic Nginx configuration.

Read this article

  • The installation of the Nginx
  • Nginx configuration resolution

Nginx installation

  • Use Homebrew to download Nginx Brew install Nginx

  • After a successful Nginx download, it is important to have two directories

    • /usr/local/etc/nginxThe default installation directory of Nginx

    • /usr/local/var/wwwNginx server file storage location

Nginx-related operations

Introduces some basic and common terminal syntax for using Nginx.

  • Enter the/usr/local/etc/nginx
  • performsudo nginx -c nginx.conf, Nginx starts with the default configuration
  • sudo nginx -s reloadGracefully restart Nginx
  • sudo nginx -s quitExit the Nginx

Nginx configuration

Nginx Worker processes run on user *** by default, the nobody account runs on user ***. # Nginx Number of processes, recommended to be equal to the total number of CPU cores. worker_processes 4; # define global error log type, the debug | info | notice | warn | error | crit], in which the debug output log is most the most detailed, and crit output log at least error_log logs/error. The log info; Pid logs/nginx.pid; # The maximum number of file descriptors that can be opened by an nginx process. The theory value should be the maximum number of open files (ulimit -n) divided by the number of Nginx processes. However, nginx does not allocate requests evenly, so it is recommended to keep the same as ulimit -n. You can use the "ulimit -n 65535" command to set other values. worker_rlimit_nofile 4864; # # working mode and the upper limit of the number of connections events {reference event model, use [kqueue | rtsig | epoll | / dev/poll | select | poll]; The EPoll model is a high performance network I/O model in Linux kernel versions above 2.6, and the KQueue model is used if running on FreeBSD. use epoll; #worker_connections specifies the maximum number of connections per process in Nginx, which is the maximum number of requests received from the front end. Default is 1024. The maximum number of client connections is determined by worker_Processes and worker_connections. That is, Max_clients=worker_processes*worker_connections. When working as a reverse proxy, Max_clients becomes: Max_clients = worker_PROCESSES * worker_connections/4. The maximum number of connections for a process is limited by the maximum number of open files for a Linux process. The setting of worker_connections takes effect only after you run the ulimit -n 65536 command. HTTP {# tells nginx to identify the file type with the mime type defined in the mime.type file in the configuration file directory. include mime.types; default_type application/octet-stream; # default file type #charset utF-8; The default encoding is used to set the format of the log and what parameters to log. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '#'$status $body_bytes_sent "$http_referer" ' #'"$http_user_agent" "$http_x_forwarded_for"'; sendfile on; To enable efficient file transfer mode, the sendfile directive specifies whether nginx will call sendfile to output files. This is set to on for common applications and to off for applications with heavy disk I/O loads, such as downloads, to balance disk and network I/O processing speed and reduce system load. Note: Change this to OFF if the image is not showing properly. autoindex on; # Enable directory list access, suitable for download server, disable by default. tcp_nopush on; Tcp_nodelay on; Keepalive_timeout 120; The FastCGI parameters are designed to improve the performance of your site: reduce resource usage and increase access speed. The following parameters can be read literally. fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 128k; Set gzip on; Gzip_min_length 1k; Gzip_buffers 4 16k; # Compression buffer gzip_http_version 1.0; Compressed version (default 1.1, use 1.0 if squid2.5) gzip_comp_level 2; Gzip_types text/plain application/x-javascript text/ CSS application/ XML; The default compression type already contains text/ HTML, so you don't need to write it again. gzip_vary on; #limit_zone crawler $binary_remote_addr 10m; Use "upstream blog.ha97.com" when limiting the number of IP connections. The weigth parameter represents the weight, the higher the weight, the greater the probability of being assigned. Server 192.168.80.121:80 weight = 3; Server 192.168.80.122:80 weight = 2; Server 192.168.80.123:80 weight = 3; } server {# listen to port 80; Server_name WWW.***.com ***.com; index index.html index.htm index.php; # indicates all root web root directories within the entire server virtual host. Root /data/ WWW /***; Location /mp/ {proxy_pass http://127.0.0.1:8080; proxy_set_header Host $host; } the location / {proxy_pass http://192.168.200.248:80; proxy_set_header Host $host; } # prohibited page caching location ~ * \. (js | | CSS PNG | JPG | GIF) ${add_header cache-control no - the store; } add_header Access-Control-Allow-Origin "*"; }}Copy the code

Write in the last

If you find this article helpful, please like it and share it with more people who need it!

Welcome to pay attention to [Quanzhendaolu] and wechat public account [Quanzhendaolu], to get more good articles and free books!
There is a need [Baidu] & [bytedance] & [JD] & [ape counselling] within the push, please leave a message oh, you will enjoy the VIP level extreme speed within the push service ~

Past oliver

Wechat JS API payment implementation

Create a personalized Github profile

The interviewer asks you<img>What elements do you say

Special JS floating point number storage and calculation

Long [word] baidu and good interview after containing the answer | the nuggets technology essay in the future

Front end practical regular expression & tips, all throw you 🏆 nuggets all technical essay | double festival special articles

HTML Tabindex

A few lines of code to teach you to solve wechat poster and TWO-DIMENSIONAL code generation

Vue3.0 Responsive data principle: ES6 Proxy

Read on to make your interviewer fall in love with you

How to draw a fine line gracefully

Front-end performance optimization -HTML, CSS, JS parts

Front-end performance optimization – Page loading speed optimization

Front-end performance optimization – Network transport layer optimization