How to implement nginx reverse proxy in Centos7

WBOY
Release: 2023-06-02 20:16:01
forward
1116 people have browsed it

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.

How to implement nginx reverse proxy in Centos7

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
Copy after login
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
Copy after login
Configuration file

(below The operation is performed on web01 and web02)

[root@localhost ~]# vim /app/nginx/conf/nginx.conf
Copy after login
Copy after login

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
Copy after login

(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
Copy after login

Use curl bbs.dengch How to implement nginx reverse proxy in Centos7, the following operations are performed on the nginx load balancer

[root@localhost ~]# vim /app/nginx/conf/nginx.conf
Copy after login
Copy after login

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
Copy after login

Check the syntax

[root@localhost ~]# /app/nginx/sbin/nginx -t
Copy after login

Start the service

[root@localhost ~]# /app/nginx/sbin/nginx
Copy after login

How to implement nginx reverse proxy in Centos7 Use curl www.dengchuanghai.org How to implement nginx reverse proxy in Centos7 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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!