Reverse proxy server is set up on the server side to alleviate the workload of the server by buffering frequently requested pages and forward client requests to the target server on the internal network; and The results obtained from the server are returned to the client requesting a connection on the Internet. At this time, the proxy server and the target host appear as a server to the outside world. Currently, web websites use reverse proxies, which in addition to preventing vicious attacks from the external network on internal servers, caching to reduce server pressure and access security control.

Experimental environment:
192.168.1.188 nginx load balancer
192.168.1.189 web01 server
192.168. 1.190 web02 server
Software preparation:
centos7.4 x86_64
nginx-1.6.3.tar.gz
Install nginx software
Install dependent software package command collection
[root@localhost ~]# yum -y install openssl openssl-devel pcre pcre-devel gcc
Install nginx software package command collection
[root@localhost ~]# mkdir /app[root@localhost ~]# cd /app[root@localhost ~]# wget -q http://nginx.org/download/nginx-1.6.3.tar.gz[root@localhost ~]# useradd -s /sbin/nologin -M[root@localhost ~]# tar xf nginx-1.6.3.tar.gz[root@localhost ~]# cd nginx-1.6.3[root@localhost ~]# ./configure --user=nginx --group=nginx --prefix=/app/nginx --with-http_stub_status_module --with-http_ssl_module[root@localhost ~]# make && make install
Configuration file
(below The operation is performed on web01 and web02)
[root@localhost ~]# vim /app/nginx/conf/nginx.conf
Modify the configuration file to the following content
worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; log_format main '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "http_referer" ''"$http_user_agent" " $http_x_forwarded_for"'; server { listen 80; server_name bbs.dengchuanghai.org; location / { root html/bbs; index index.html index.htm; } access_log logs/access_bbs.log main; } } [root@localhost ~]# mkdir /app/nginx/html/bbs[root@localhost ~]# echo "192.168.1.189 bbs" >>/app/nginx/html/bbs/index.html [root@localhost ~]# echo "192.168.1.189 bbs.dengchuanghai.org" >> /etc/hosts [root@localhost ~]# echo "192.168.1.190 bbs" >>/app/nginx/html/bbs/index.html [root@localhost ~]# echo "192.168.1.190 bbs.dengchuanghai.org" >> /etc/hosts
(Enter the above content on the two web servers respectively)
Then start them respectively nginx
[root@localhost ~]# /app/nginx/sbin/nginx -t (检查配置文件有无错误)[root@localhost ~]# /app/nginx/sbin/nginx 启动[root@localhost ~]# ss -tnlp | grep 80
Use curl bbs.dengch , the following operations are performed on the nginx load balancer
[root@localhost ~]# vim /app/nginx/conf/nginx.conf
Change to the following
worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; upstream www_server_pools{ server 192.168.1.190:80 weight=1; server 192.168.1.189:80 weight=1; } server { listen 80; server_name www.dengchuanghai.org; location / { proxy_pass http://www_server_pools; } } } [root@localhost ~]# echo "192.168.1.188 www.dengchuanghai,org" >> /etc/hosts
Check the syntax
[root@localhost ~]# /app/nginx/sbin/nginx -t
Start the service
[root@localhost ~]# /app/nginx/sbin/nginx
Use curl www.dengchuanghai.org
The result output is found to be output by two servers in turn
The above is the detailed content of How to implement nginx reverse proxy in Centos7. For more information, please follow other related articles on the PHP Chinese website!

NGINX can improve website performance and reliability by: 1. Process static content as a web server; 2. forward requests as a reverse proxy server; 3. allocate requests as a load balancer; 4. Reduce backend pressure as a cache server. NGINX can significantly improve website performance through configuration optimizations such as enabling Gzip compression and adjusting connection pooling.

NGINXserveswebcontentandactsasareverseproxy,loadbalancer,andmore.1)ItefficientlyservesstaticcontentlikeHTMLandimages.2)Itfunctionsasareverseproxyandloadbalancer,distributingtrafficacrossservers.3)NGINXenhancesperformancethroughcaching.4)Itofferssecur

NGINXUnit simplifies application deployment with dynamic configuration and multilingual support. 1) Dynamic configuration can be modified without restarting the server. 2) Supports multiple programming languages, such as Python, PHP, and Java. 3) Adopt asynchronous non-blocking I/O model to improve high concurrency processing performance.

NGINX initially solved the C10K problem and has now developed into an all-rounder who handles load balancing, reverse proxying and API gateways. 1) It is well-known for event-driven and non-blocking architectures and is suitable for high concurrency. 2) NGINX can be used as an HTTP and reverse proxy server, supporting IMAP/POP3. 3) Its working principle is based on event-driven and asynchronous I/O models, improving performance. 4) Basic usage includes configuring virtual hosts and load balancing, and advanced usage involves complex load balancing and caching strategies. 5) Common errors include configuration syntax errors and permission issues, and debugging skills include using nginx-t command and stub_status module. 6) Performance optimization suggestions include adjusting worker parameters, using gzip compression and

Diagnosis and solutions for common errors of Nginx include: 1. View log files, 2. Adjust configuration files, 3. Optimize performance. By analyzing logs, adjusting timeout settings and optimizing cache and load balancing, errors such as 404, 502, 504 can be effectively resolved to improve website stability and performance.

NGINXUnitischosenfordeployingapplicationsduetoitsflexibility,easeofuse,andabilitytohandledynamicapplications.1)ItsupportsmultipleprogramminglanguageslikePython,PHP,Node.js,andJava.2)Itallowsdynamicreconfigurationwithoutdowntime.3)ItusesJSONforconfigu

NGINX can be used to serve files and manage traffic. 1) Configure NGINX service static files: define the listening port and file directory. 2) Implement load balancing and traffic management: Use upstream module and cache policies to optimize performance.

NGINX is suitable for handling high concurrency and static content, while Apache is suitable for dynamic content and complex URL rewrites. 1.NGINX adopts an event-driven model, suitable for high concurrency. 2. Apache uses process or thread model, which is suitable for dynamic content. 3. NGINX configuration is simple, Apache configuration is complex but more flexible.


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Chinese version
Chinese version, very easy to use

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
