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

Overview and deployment of nginx reverse proxy

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

The following gives you an overview and deployment of nginx reverse proxy, hoping to give you some help in practical application. Load balancing involves more things, not much theory, and there are many books on the Internet. Today, we will use the accumulated experience in the industry to do an answer.

1. Overview of reverse proxy

Reverse proxy (Reverse Proxy) means that the proxy cloud server accepts the connection request on the internet, then forwards the request to the server on the internal network, and returns the result obtained from the server to the client requesting the connection on the internet. In this case, the proxy server appears as a reverse proxy server.

Environmental preparation:

Hostname IP address role system web-node1.cometh0:192.168.90.201web-node1 node CentOS7.2web-node2.cometh0:192.168.90.202web-node2 node CentOS7.2lb-node1.cometh0:192.168.90.203Nginx reverse proxy CentOS7.22.Node node deployment

Use Yum in both web-node nodes to install an Apache for real machine, listening on port 8080

Web-node1.com deployment

[root@web-node1 ~] # rpm-ivh http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm[root@web-node1 ~] # yum install-y gcc glibc gcc-c++ make screen tree lrzsz## deployment web-node1 httpd Service [root@web-node1 ~] # yum install-y httpd [root@web-node1 ~] # sed-I 's/Listen 80/Listen 8080DB g' / etc/httpd/conf/httpd.conf [root@web- Node1 ~] # systemctl start httpd [root@web-node1 ~] # echo "web-node1.com" > / var/www/html/index.html [root@web-node1 ~] # curl http://192.168.90.201:8080/web-node1.com

Web-node2.com deployment

[root@web-node1 ~] # rpm-ivh http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm[root@web-node1 ~] # yum install-y gcc glibc gcc-c++ make screen tree lrzsz## deployment web-node2 httpd Service [root@web-node1 ~] # yum install-y httpd [root@web-node1 ~] # sed-I 's/Listen 80/Listen 8080DB g' / etc/httpd/conf/httpd.conf [root@web- Node1 ~] # systemctl start httpd [root@web-node1 ~] # echo "web-node2.com" > / var/www/html/index.html [root@web-node1 ~] # curl http://192.168.90.202:8080/web-node2.com3. Reverse proxy deployment

Nginx source code compiles and installs to support layer 4 and listens on port 80

[root@lb-node1] # useradd-s / sbin/nologin-M www

[root@lb-node1 ~] # cd / usr/local/src/

[root@lb-node1 src] # wget http://nginx.org/download/nginx-1.10.2.tar.gz

[root@lb-node1 src] # tar xf nginx-1.10.2.tar.gz

[root@lb-node1 src] # cd nginx-1.10.2

[root@lb-node1 nginx-1.10.2] #. / configure-- prefix=/usr/local/nginx-1.10.2\

-user=www-group=www-with-http_ssl_module\

-with-http_stub_status_module-with-file-aio-with-stream

[root@lb-node1 nginx-1.10.2] # make & & make install

[root@web-node1] # ln-s / usr/local/nginx-1.10.2/ / usr/local/nginx

# # testing configuration and starting Nginx

[root@lb-node1] # / usr/local/nginx/sbin/nginx-t

Nginx: the configuration file / usr/local/nginx-1.10.2/conf/nginx.conf syntax is ok

Nginx: configuration file / usr/local/nginx-1.10.2/conf/nginx.conf test is successful

[root@lb-node1 ~] # / usr/local/nginx/sbin/nginx

Configure Nginx7 layer reverse proxy 1. Configure Nginx reverse proxy

# # http segment configuration

Upstream web-cluster {

# ip_hash

Server 192.168.90.201:8080 weight=1 max_fails=3 fail_timeout=3

Server 192.168.90.202:8080 weight=1 max_fails=3 fail_timeout=3

}

Server {

Listen 80

Server_name 192.168.90.203

Location / {

Proxy_pass http://web-cluster;

Include proxy.conf

}

}

Test agent

[root@lb-node1 ~] # curl http://192.168.90.203/

Web-node1.com

[root@lb-node1 ~] # curl http://192.168.90.203/

Web-node2.com

[root@lb-node1 ~] # curl http://192.168.90.203/

Web-node1.com

[root@lb-node1 ~] # curl http://192.168.90.203/

Web-node2.com

two。 Implement different agents through grouping and User-agent

# http segment configuration

Upstream static-cluster {

Server 192.168.90.201:8080 weight=1 max_fails=3 fail_timeout=3

}

Upstream dynamic-cluster {

Server 192.168.90.202:8080 weight=1 max_fails=3 fail_timeout=3

}

Upstream default-cluster {

Server 192.168.90.202:8080 weight=1 max_fails=3 fail_timeout=3

}

# need to configure local host parsing test server {listen 80; server_name nginx.jiege.com; location / {if ($http_user_agent ~ * "Firefox") {proxy_pass http://static-cluster; } if ($http_user_agent ~ * "Chrome") {proxy_pass http://dynamic-cluster;} proxy_pass http://default-cluster;}}

Test grouping

# # default browser to default processing [root@lb-node1 ~] # curl http://nginx.jiege.com web-node2.com Firefox browser to static-cluster processing Google browser to dynamic-cluster processing configuration ssh and msql reverse proxy stream {upstream ssh_proxy {hash $remote_addr consistent; server 192.168.90.201V22;} upstream mysql_proxy {hash $remote_addr consistent Server 192.168.90.202 server 3306;} server {listen 2222; proxy_connect_timeout 1s; proxy_timeout 300s; proxy_pass ssh_proxy;} server {listen 3333; proxy_connect_timeout 1s; proxy_timeout 300s; proxy_pass mysql_proxy;}}

2222 port agent as for node1's SSH, 3333 port agent as for node2's MYSQL

# # testing connection to ssh

[root@lb-node1] # ssh-p2222 root@192.168.90.203

Root@192.168.90.203's password:

Last login: Wed Oct 19 11:53:04 2016 from 192.168.80.143

[root@web-node1 ~] #

# # testing connection to mysql

[root@lb-node1] # mysql-h392.168.90.203-uroot-p1-P3333

Welcome to the MariaDB monitor. Commands end with; or\ g.

Your MariaDB connection id is 273

Server version: 5.5.47-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or'\ h' for help. Type'\ c'to clear the current input statement.

MariaDB [(none)] >

After reading the above overview and deployment of nginx reverse proxy, if you have anything else you need to know, you can find what you are interested in in the industry information or find our professional technical engineer to answer, the technical engineer has more than ten years of experience in the industry.

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

Servers

Wechat

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

12
Report