欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

nginx實現(xiàn)動靜分離實例講解

 更新時間:2020年03月12日 08:49:03   作者:夜鶯。  
在本篇文章里小編給大家整理的是關(guān)于nginx實現(xiàn)動靜分離實例講解,需要的朋友們可以參考下。

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

1、準(zhǔn)備環(huán)境

準(zhǔn)備一個nginx代理 兩個http 分別處理動態(tài)和靜態(tài)。

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
#動態(tài)資源加載
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;
}

#靜態(tài)資源加載
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;
}
}

靜態(tài)資源配置---10.0.105.196

server {
listen 80;
server_name localhost;

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

上傳圖片

動態(tài)資源配置: 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; #指定網(wǎng)站目錄

fastcgi_pass fastcgi_index fastcgi_param

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

include

}

}

127.0.0.1:9000; #指定訪問地址

index.php;

#指定默認(rèn)文件

SCRIPT_FILENAME $document_root$fastcgi_script_name;

fastcgi_params; #包含nginx常量定義

當(dāng)訪問靜態(tài)頁面的時候location 匹配到 (html|jpg|png|js|css) 通過轉(zhuǎn)發(fā)到靜態(tài)服務(wù)器,靜態(tài)服務(wù)通過

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

當(dāng)訪問動態(tài)頁面時location匹配到 .\php 結(jié)尾的文件轉(zhuǎn)發(fā)到后端php服務(wù)處理請求。

知識點擴展:

通過請求分離

[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

根據(jù)擴展名分離

[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

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

相關(guān)文章

  • 在網(wǎng)關(guān)中使用Nginx配置HTTP透明代理案例

    在網(wǎng)關(guān)中使用Nginx配置HTTP透明代理案例

    這篇文章主要介紹了在網(wǎng)關(guān)中使用Nginx配置HTTP透明代理案例,中間還需要iptables配合,需要的朋友可以參考下
    2014-06-06
  • nginx代理實現(xiàn)靜態(tài)資源訪問的示例代碼

    nginx代理實現(xiàn)靜態(tài)資源訪問的示例代碼

    本文主要介紹了nginx代理實現(xiàn)靜態(tài)資源訪問的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-06-06
  • Nginx為Tomcat服務(wù)器作反向代理的配置教程

    Nginx為Tomcat服務(wù)器作反向代理的配置教程

    這篇文章主要介紹了Nginx為Tomcat服務(wù)器作反向代理的配置教程,文中以Windows系統(tǒng)為環(huán)境來演示驅(qū)動JSP程序的示例,需要的朋友可以參考下
    2016-03-03
  • Nginx網(wǎng)站服務(wù)過程詳解

    Nginx網(wǎng)站服務(wù)過程詳解

    Nginx是一款高性能、異步非阻塞工作模式、輕量級Web服務(wù)軟件,這篇文章主要介紹了Nginx網(wǎng)站服務(wù)的相關(guān)知識,需要的朋友可以參考下
    2023-06-06
  • 分享最新版 nginx內(nèi)置變量 大全

    分享最新版 nginx內(nèi)置變量 大全

    在配置基于nginx服務(wù)器的網(wǎng)站時,必然會用到 nginx內(nèi)置變量 ,下面筆者將它整理成列表,把最新版本的變量列出來,以方便做配置時查詢
    2016-04-04
  • 解決使用了nginx獲取IP地址都是127.0.0.1 的問題

    解決使用了nginx獲取IP地址都是127.0.0.1 的問題

    這篇文章主要介紹了解決使用了nginx獲取IP地址都是127.0.0.1 的問題,獲取i工具的完整代碼文中給大家提到,具體實例代碼跟隨小編一起看看吧
    2021-09-09
  • nginx實現(xiàn)數(shù)據(jù)庫端口轉(zhuǎn)發(fā)

    nginx實現(xiàn)數(shù)據(jù)庫端口轉(zhuǎn)發(fā)

    本文主要介紹了nginx實現(xiàn)數(shù)據(jù)庫端口轉(zhuǎn)發(fā),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-03-03
  • nginx 負(fù)載均衡 多站點共享Session

    nginx 負(fù)載均衡 多站點共享Session

    這里我們就 演練一下 以數(shù)據(jù)庫的形來存儲Session,來實現(xiàn)多站點共享Session
    2012-11-11
  • nginx如何開通gzip壓縮傳輸文件

    nginx如何開通gzip壓縮傳輸文件

    Gzip壓縮是一種有效提升網(wǎng)站性能的方法,通過減少傳輸數(shù)據(jù)量和提高傳輸速度,Nginx服務(wù)器支持Gzip壓縮,適合壓縮HTML、CSS、JavaScript、JSON和XML等文本文件,配置中需設(shè)置gzip_types指定壓縮文件類型,gzip_comp_level設(shè)置壓縮級別
    2024-09-09
  • OpenResty中實現(xiàn)按QPS、時間范圍、來源IP進(jìn)行限流的方法

    OpenResty中實現(xiàn)按QPS、時間范圍、來源IP進(jìn)行限流的方法

    OpenResty是一個基于Nginx與Lua的高性能Web平臺,它通過LuaJIT在Nginx中運行高效的Lua腳本和模塊,可以用來處理復(fù)雜的網(wǎng)絡(luò)請求,并且支持各種流量控制和限制的功能,這篇文章主要介紹了OpenResty中實現(xiàn)按QPS、時間范圍、來源IP進(jìn)行限流,需要的朋友可以參考下
    2024-02-02

最新評論