Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement nginx reverse proxy with Centos7

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "Centos7 how to achieve nginx reverse proxy", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "Centos7 how to achieve nginx reverse proxy" bar!

The reverse proxy server is set up on the server side, which alleviates the workload of the server by buffering the frequently requested pages, forwards the client request to the target server on the internal network, and returns the result obtained from the server to the client requesting connection on the Internet. At this time, the proxy server behaves as a server with the target host. At present, web website uses reverse proxy, in addition to preventing the external network from vicious attacks on the intranet server, caching to reduce the pressure on the server 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 installation dependent package command set [root@localhost ~] # yum-y install openssl openssl-devel pcre pcre-devel gcc install nginx package command set [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

(the following is done on web01 and web02)

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

Modify the configuration file to

Worker_processes 1 status events {worker_connections 1024;} http {listen 65 × logarithmic 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 / serveraccounname 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 on two web servers)

Then start nginx separately

[root@localhost ~] # / app/nginx/sbin/nginx-t (check the configuration file for errors) [root@localhost ~] # / app/nginx/sbin/nginx launch [root@localhost ~] # ss-tnlp | grep 80

Using curl bbs.dengch, the following is done on the nginx load balancer

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

Change to the following

Worker_processes 1 server events {worker_connections 1024;} http {include mime.types;default_type application/octet-stream;sendfile on;keepalive_timeout 65 scene upstream www_server_pools {server 192.168.1.190 weight=1;server 80 weight=1;server 192.168.1.189 worker_connections} server {listen 80 weight=1; www.dengchuanghai.org;location / {proxy_pass events ~] # echo "192.168.1.188 www.dengchuanghai,org" > > / etc/hosts

Check the grammar

[root@localhost] # / app/nginx/sbin/nginx-t

Start the service

[root@localhost ~] # / app/nginx/sbin/nginx

Use curl www.dengchuanghai.org to output the discovery results in turn between the two servers

At this point, I believe you have a deeper understanding of "Centos7 how to achieve nginx reverse proxy". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report