Nginx server configuration instructions
Nginx server configuration instructions:
Rewrite function, proxy function
Rewrite function
Configuration instructions of the back-end server group
upstream instruction
upstream instruction is the main instruction to set up the back-end server group
<code>upstream name {<span>...</span>} </code>
Requests are scheduled according to round-robin (RR) Policy order selection server processing
server
server directive is used to set the server in the group
<code>server address [<span>params</span>];</code>
- address: server address, which can include a port number or a Unix Domain Socket for inter-process communication prefixed with "unix:"
- params: configure more properties for the current server.
weight=number, the weight of the servers in the group, requests with higher weights will be processed first (weighted polling strategy is adopted)
max_fails=number, sets the number of failed requests. When the number of failed requests to a server in the group exceeds this variable, the server is considered invalid (except 404)
fail_timeout=time, set the time to try to request a server in a group and check whether the server is valid
backup, mark the server as a backup server
down, marking the server as permanently invalid
ip_hash command
ip_hash command is used to implement the session persistence function, directing multiple requests from a client to the same server in the group to ensure a stable session between the client and the server .
Note: The ip_hash command cannot be used with the weight variable. In the entire system, the Nginx server must be the front-end server, and the client address must be a Class C address.
keepalive command
keepalive command is used to control network connection maintenance Function
<code>keepalive connections;</code>
Set the upper limit of the number of idle network connections that each worker process of the server allows the server group to maintain
least_conn directive
least_conn directive is used to configure the Nginx server to use a load balancing strategy to allocate network connections within the server group Server, allocate requests to the server with the least current network connection
Configuration instructions for the Rewrite function
Multiple applications of the Rewrite function
Proxy function
Nginx forward proxy service configuration instructions
resolver instructions
resolver instructions are used Specify the IP address of the DNS server
<code>resolver address <span>...</span> [valid=time];</code>
- address, the IP address of the DNS server, the default port is 35
- time, set the validity time of the data packet in the network
resolve_timeout command
resolve_timeout command is used to set the DNS server domain name resolution Timeout time
<code>resolve_timeout <span>time</span>;</code>
proxy_pass command
proxy_pass command is used to set the protocol and address of the proxy server
<code>proxy_pass <span>URL</span>;</code>
Nginx reverse proxy service configuration command
proxy_pass command
proxy_pass command is used to set the address of the proxy server, which can be the host Name, IP address plus port number, etc.
<code>proxy_pass <span>URL</span>;</code>
proxy_hide_header command
proxy_hide_header command is used to set the Nginx server to hide some header field information when sending HTTP responses
<code>proxy<span>\_</span>hide_header field</code>
proxy_pass_header command
proxy_pass_header command is used to set those header field information is sent
<code>proxy<span>\_</span>hide_header field</code>
proxy_pass_header directive
proxy_pass_header directive is used to set which header field information is sent
<code>proxy<span>\_</span>hide_header field</code>
omitted
Nginx reverse proxy service - load balancing
load balancing of general polling rules
<code><span>...</span> upstream backend { server <span>192.168</span><span>.1</span><span>.2</span>:<span>80</span>; server <span>192.168</span><span>.1</span><span>.3</span>:<span>80</span>; server <span>192.168</span><span>.1</span><span>.4</span>:<span>80</span>; } server { listen <span>80</span>; server_name www.mysite.name; index index.html index.htm; location / { proxy_pass http://backend; proxy_set_header Host $host; <span>...</span> } <span>...</span> }</code>
weighted polling rules Load balancing
<code><span>...</span> upstream backend { server <span>192.168</span><span>.1</span><span>.2</span>:<span>80</span> weight=<span>5</span>; server <span>192.168</span><span>.1</span><span>.3</span>:<span>80</span> weight=<span>2</span>; server <span>192.168</span><span>.1</span><span>.4</span>:<span>80</span>; } server { listen <span>80</span>; server_name www.mysite.name; index index.html index.htm; location / { proxy_pass http://backend; proxy_set_header Host $host; <span>...</span> } <span>...</span> }</code>
Load balancing of specific resources
<code><span>...</span> upstream videobackend { server <span>192.168</span><span>.1</span><span>.2</span>:<span>80</span>; server <span>192.168</span><span>.1</span><span>.3</span>:<span>80</span>; server <span>192.168</span><span>.1</span><span>.4</span>:<span>80</span>; } upstream filebackend { server <span>192.168</span><span>.1</span><span>.5</span>:<span>80</span>; server <span>192.168</span><span>.1</span><span>.6</span>:<span>80</span>; server <span>192.168</span><span>.1</span><span>.7</span>:<span>80</span>; } server { listen <span>80</span>; server_name www.mysite.name; index index.html index.htm; location /video/ { proxy_pass http://videobackend; proxy_set_header Host $host; <span>...</span> } location /file/ { proxy_pass http://filebackend; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; <span>...</span> } <span>...</span> }</code>
Load balancing for different domain names
<code><span>...</span> upstream bbsbackend{ server <span>192.168</span><span>.1</span><span>.2</span>:<span>80</span> weight=<span>2</span>; server <span>192.168</span><span>.1</span><span>.3</span>:<span>80</span> weight=<span>2</span>; server <span>192.168</span><span>.1</span><span>.4</span>:<span>80</span>; } upstream homebackend { server <span>192.168</span><span>.1</span><span>.4</span>:<span>80</span>; server <span>192.168</span><span>.1</span><span>.5</span>:<span>80</span>; server <span>192.168</span><span>.1</span><span>.6</span>:<span>80</span>; } server { listen <span>80</span>; server_name home.mysite.name; index index.html index.htm; location / { proxy_pass http://homebackend; proxy_set_header Host $host; <span>...</span> } <span>...</span> } server { listen <span>81</span>; server_name bbs.mysite.name; index index.html index.htm; location / { proxy_pass http://bbsbackend; proxy_set_header Host $host; <span>...</span> } <span>...</span> }</code>
Load balancing with URL rewriting
<code><span>...</span> upstream backend{ server <span>192.168</span><span>.1</span><span>.2</span>:<span>80</span>; server <span>192.168</span><span>.1</span><span>.3</span>:<span>80</span>; server <span>192.168</span><span>.1</span><span>.4</span>:<span>80</span>; } server { listen <span>80</span>; server_name www.mysite.name; index index.html index.htm; location /file/ { rewrite ^(/file/.*)/media/(.*)\.*$ $<span>1</span>/mp3/$<span>2.</span>mp3 last; } location / { proxy_pass http://backend; proxy_set_header Host $host; <span>...</span> } }</code>
The above introduces the Nginx server configuration instructions, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



index.html represents the home page file of the web page and is the default page of the website. When a user visits a website, the index.html page is usually loaded first. HTML (HypertextMarkupLanguage) is a markup language used to create web pages, and index.html is also an HTML file. It contains the structure and content of a web page, as well as tags and elements used for formatting and layout. Here is an example index.html code: <

Overview of NginxProxyManager configuration analysis and optimization: NginxProxyManager is a reverse proxy management tool based on Nginx, which can help us easily configure and manage reverse proxy servers. In the process of using NginxProxyManager, we can improve the performance and security of the server by parsing and optimizing its configuration. Configuration analysis: Configuration file location and structure: NginxProxyManag

When proxyprotocol is used in nginx, we know that nginx is a web server and proxy server. It generally works behind proxyserver or load balancing software (Haproxy, Amazon Elastic LoadBalancer (ELB)). The client first requests proxyserver or LSB load balancing software, and then to nginx Perform real web access. Because it has gone through multiple layers of software, some client information such as IP address, port number, etc. may be hidden, which is detrimental to our problem analysis and data statistics. Because for nginx, We want to be able to get real clients

The deployment strategy of containers and microservices under NginxProxyManager requires specific code examples. Summary: With the popularity of microservice architecture, containerization technology has become an important part of modern software development. In the microservice architecture, NginxProxyManager plays a very important role, used to manage and proxy the traffic of microservices. This article will introduce how to use NginxProxyManager to deploy and manage containerized microservices, and provide relevant code examples.

How to use NginxProxyManager to achieve load balancing of multiple servers. NginxProxyManager is a proxy server management tool developed based on Nginx. It provides a simple and easy-to-use Web interface that can easily configure and manage Nginx proxy servers. In practical applications, we often need to distribute requests to multiple servers to achieve load balancing and improve system performance and availability. This article will introduce how to use NginxProx

NginxProxyManager Tutorial: Quick Start Guide, Specific Code Examples Needed Introduction: With the development of network technology, proxy servers have become a part of our daily use of the Internet. NginxProxyManager is a proxy server management platform based on Nginx, which can help us quickly establish and manage proxy servers. This article will introduce you to the quick start guide of NginxProxyManager, as well as some specific code examples. one

WindowsServerBackup is a function that comes with the WindowsServer operating system, designed to help users protect important data and system configurations, and provide complete backup and recovery solutions for small, medium and enterprise-level enterprises. Only users running Server2022 and higher can use this feature. In this article, we will explain how to install, uninstall or reset WindowsServerBackup. How to Reset Windows Server Backup If you are experiencing problems with your server backup, the backup is taking too long, or you are unable to access stored files, then you may consider resetting your Windows Server backup settings. To reset Windows

[SpringBoot] Passing parameters in the Header through Feign calls How to pass Header parameters through Feign Problem description When we use Feign to request the Api interface of another service in Spring Cloud, there is a need to pass the parameters in the Header. If no special processing is done, it will The parameters in the Header will be lost. Solution 1: Pass it through @RequestHeader(name="headerName"). For example: Feign is defined as follows @FeignClient(name="service-name")pub
