In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to achieve static and dynamic separation of nginx. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
In order to speed up the parsing speed of the website, dynamic pages and static pages can be parsed by different servers to accelerate the parsing speed. Reduce the pressure on a single server. To put it simply, use regular expressions to match and filter, and then hand over to a different server.
1. Prepare the environment
Prepare a nginx agent and two http to handle dynamic and static, respectively.
1. Configure the compiled and installed nginx to reverse proxy upstream
Upstream static {server 10.0.105.196server 80 weight=1 max_fails=1 fail_timeout=60s;} upstream php {server 10.0.105.200 server 80 weight=1 max_fails=1 fail_timeout=60s;} server {listen server_name# dynamic resource loading 80 localhostlocation ~\. (php | jsp) ${proxy_pass proxy_pass Host $host:$server_port; proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for } # static resource loading location ~\. (html | jpg | png | 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;}}
Static resource allocation-10.0.105.196
Server {listen 80th serverroomname localhost;location ~\. (html | jpg | png | js | css) ${root / var/www/nginx;}}
Upload pictures
Dynamic resource allocation: 10.0.105.200
Yum install 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:
[root@nginx-server ~] # cd / etc/nginx/conf.d/ [root@nginx-server conf.d] # vim phpserver.conf server {
Listen 80
Server_name localhost; location ~\ .php$ {
Root / home/nginx/html; # specifies the website directory
Fastcgi_pass fastcgi_index fastcgi_param
# site root directory, depending on root configuration item
Include
}
}
127.0.0.1virtual 9000; # specify the access address
Index.php
# specify default file
SCRIPT_FILENAME $document_root$fastcgi_script_name
Fastcgi_params; # contains nginx constant definition
When visiting a static page, the location matches to (html | jpg | png | js | css) by forwarding to the static server, and the static service passes through
Regular matching of location to process the request.
When accessing a dynamic page, the file that location matches to the end of.\ php is forwarded to the back-end php service to process the request.
Knowledge point expansion:
By requesting separation
[root@lb01 conf] # vim nginx.confworker_processes 1: events {worker_connections 1024;} http {include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; upstream stack_pools {server 172.25.254.134 weight=5; 80 weight=5;} upstream dynamic_pools {server 172.25.254.135 weight=5; 80 weight=5;} server {listen 80; server_name www.lbtest.com; location / {root html Index index.html index.htm; proxy_set_header Host $host; proxy_pass http://dynamic_pools;} location / image/ {proxy_set_header Host $host; proxy_pass http://stack_pools;} location / dynamic/ {proxy_set_header Host $host; proxy_pass http://dynamic_pools;} [root@lb01 conf] # nginx-s reload
Separate by extension
[root@lb01 conf] # vim nginx.conf worker_processes 1: events {worker_connections 1024;} http {include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; upstream stack_pools {server 172.25.254.134 weight=5; 80 weight=5;} upstream dynamic_pools {server 172.25.254.135 weight=5; 80 weight=5;} server {listen 80; server_name www.lbtest.com; location / {root html Index index.html index.htm; proxy_set_header Host $host; proxy_pass http://dynamic_pools;} location ~. *. (jpg | png | gif | css | js | swf | bmp | jsp | php | asp) ${proxy_set_header Host $host; proxy_pass http://stack_pools; } [root@lb01 conf] # nginx-s reload article on "how to achieve dynamic and static separation in nginx" ends here. I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.