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

Implementation of nginx proxy server based on Linux Centos7 and methods and steps of static and dynamic separation

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

Share

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

The following brings you the methods and steps of implementing nginx proxy cloud servers and dynamic separation based on Linux Centos7, hoping to bring some help to you in practical application. There are many things involved in load balancing, there are not many theories, and there are many books on the Internet. Today, we will use the accumulated experience in the industry to do an answer.

One: environment

Prepare one nginx proxy cloud server, three http servers, two for static and one for dynamic. (nginx/1.17.3)

Configure nginx reverse proxy upstream (address pool) in the nginx main configuration file to point to the real server

Vim / etc/nginx/nginx.conf

Add to the http tag

Upstream static {server 10.30.161.214:80 weight=2 max_fails=2 fail_timeout=2s; server 10.30.161.242:80 weight=2 max_fails=2 fail_timeout=2s;} upstream php {server 10.30.161.241:80 weight=2 max_fails=2 fail_timeout=2s;}

3. In the subconfiguration file

Vim / etc/nginx/conf.d/proxy.conf

1. Dynamic resource loading

Add to the server tag

Location ~\. (php | jsp) ${proxy_pass http://phpserver; # points to the dynamic server address pool proxy_set_header Host $host:$server_port; # to redefine or add a request header to the backend server $host real server hostname $server_port port proxy_set_header X-Real-IP $remote_addr # enable the real address of the client (otherwise the log shows that the agent is visiting the website) proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # displays the real IP of the http client}

2. Static resource loading

Location ~. *\. (html | gif | jpg | png | bmp | swf | css | js) ${proxy_pass http://static; proxy_set_header Host $host:$server_port; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}

At this point, the proxy server configuration is complete

IV. Separate configuration of two static servers

Server {listen 80; server_name localhost; location ~\. (html | jpg | png | js | css | gif | bmp | jpeg) {root / web1; index index.html;}

}

Configure static projects

Static Server 1

Mkdir / web1 echo "this is jingtai11111" > / web1/index.html

Static Server 2

Mkdir / web1 echo "this id jingtai22222" > / web1/index.html

5. Separate configuration of a dynamic server

Yum installs php7.1 [root @ nginx-server ~] # rpm-Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm[root@nginx-server ~] # rpm-Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm[root@nginx-server ~] # yum install php71w-xsl php71w php71w-ldap php71w-cli php71w-common php71w-devel php71w-gd php71w-pdo php71w-mysql php71w-mbstring php71w-bcmath php71w-mcrypt-y [root@nginx- Server ~] # yum install-y php71w-fpm [root@nginx-server ~] # systemctl start php-fpm [root@nginx-server ~] # systemctl enable php-fpm

Edit the configuration file for nginx:

Server {listen 80; server_name localhost; location ~\ .php$ {root / web1; # specify the website directory fastcgi_pass 127.0.0.1 php$ 9000; # specify the access address fastcgi_index index.php; # specify the default file fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name # site root directory, depending on the root configuration item include fastcgi_params; # contains nginx constant definition}}

Configure items on dynamic web1

Mkdir / web1 cd / web1 vim index.php

VI. Testing

1. Static access test

Access proxy server IP 10.30.161.51/index.html with browser

The project on the static server / web1 can be accessed, and the two servers switch back and forth, which realizes the proxy and load balancing of nginx.

2. Dynamic access testing

Access proxy server IP 10.30.161.51/index.php with browser

The project on the dynamic server / web1 can be accessed, thus the dynamic and static separation of nginx is realized.

Read the above about Linux Centos7-based nginx proxy server and dynamic separation methods and steps, if there is anything else you need to know, you can find what you are interested in in the industry information or find our professional and technical engineers to answer, technical engineers have more than ten years of experience in the industry. Official website link www.yisu.com

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