婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > nginx實現動靜分離實例講解

nginx實現動靜分離實例講解

熱門標簽:廈門防封電銷電話卡 四川保險智能外呼系統 云南電商智能外呼系統哪家好 地圖標注能更改嗎 地圖標注員有發展前景嗎 外呼系統全國 高德地圖標注公司需要錢 宜賓銷售外呼系統軟件 濰坊寒亭400電話辦理多少錢

為了加快網站的解析速度,可以把動態頁面和靜態頁面由不同的服務器來解析,加快解析速度。降低原 來單個服務器的壓力。 簡單來說,就是使用正則表達式匹配過濾,然后交個不同的服務器。

1、準備環境

準備一個nginx代理 兩個http 分別處理動態和靜態。

1.配置編譯安裝的nginx為反向代理upstream;

upstream static {
server 10.0.105.196:80 weight=1 max_fails=1 fail_timeout=60s;
}
upstream php {
server 10.0.105.200:80 weight=1 max_fails=1 fail_timeout=60s;
}

server {
listen server_name
#動態資源加載
80;
localhost
location ~ \.(php|jsp)$ { proxy_pass http://phpserver;

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;
}

#靜態資源加載
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;
}
}

靜態資源配置---10.0.105.196

server {
listen 80;
server_name localhost;

location ~ \.(html|jpg|png|js|css)$ { root /var/www/nginx;
}
}

上傳圖片

動態資源配置: 10.0.105.200

yum 安裝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

編輯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; #指定網站目錄

fastcgi_pass fastcgi_index fastcgi_param

#站點根目錄,取決于root配置項

include

}

}

127.0.0.1:9000; #指定訪問地址

index.php;

#指定默認文件

SCRIPT_FILENAME $document_root$fastcgi_script_name;

fastcgi_params; #包含nginx常量定義

當訪問靜態頁面的時候location 匹配到 (html|jpg|png|js|css) 通過轉發到靜態服務器,靜態服務通過

location的正則匹配來處理請求。

當訪問動態頁面時location匹配到 .\php 結尾的文件轉發到后端php服務處理請求。

知識點擴展:

通過請求分離

[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:80 weight=5;
}
upstream dynamic_pools {
    server 172.25.254.135: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

根據擴展名分離

[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:80 weight=5;
}
upstream dynamic_pools {
    server 172.25.254.135: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

到此這篇關于nginx實現動靜分離實例講解的文章就介紹到這了,更多相關nginx實現動靜分離內容請搜索腳本之家以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持腳本之家!

標簽:巴彥淖爾 滁州 德州 湛江 回訪 廊坊 廣安 紅河

巨人網絡通訊聲明:本文標題《nginx實現動靜分離實例講解》,本文關鍵詞  nginx,實現,動靜,分離,實例,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《nginx實現動靜分離實例講解》相關的同類信息!
  • 本頁收集關于nginx實現動靜分離實例講解的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 禹州市| 黄龙县| 南丰县| 南安市| 喀喇沁旗| 河间市| 澄迈县| 罗定市| SHOW| 包头市| 麻江县| 密山市| 连南| 澄城县| 手游| 内江市| 绍兴市| 金沙县| 得荣县| 南开区| 教育| 钟山县| 宜丰县| 揭西县| 海宁市| 象山县| 岢岚县| 瑞金市| 罗平县| 天等县| 花莲市| 东乡族自治县| 甘孜| 惠州市| 和林格尔县| 永修县| 河津市| 栾城县| 汽车| 弥勒县| 平舆县|