Nginx和Perl的結合
在Nginx和Perl的結合中,同樣是通過Nginx的配置檔案中設定FastCGI代理來完成,而執行在後端的perl-FastCGI有三種可能,一種是perl-FastCGI執行於Unix套接字方式,那麼在這種方式中,前端的Nginx和後端的perl-FastCGI必須執行在同一臺伺服器上;第二種是perl-FastCGI執行於TCP套接字,因此,基於第二種就有分為兩種,一種是執行於本機,及前後臺同機,而另一種為前後臺不同機,所以共有三種方式。
三種結合方式
例子1、
在下面的一個例子中,前後臺分別執行在兩臺不同的機器上,例如:
前臺Nginx伺服器:
IP地址為 192.168.10.95
然後對映為外網IP,對外域名www.xx.com
後臺perl-FastCGI:
IP地址為 192.168.10.91
IP地址為 192.168.10.92
IP地址為 192.168.10.93
與前臺同機unix:/var/run/nginx/perl_cgi-dispatch.sock;
即後臺的perl-FastCGI分佈在3臺不同的機器上。
在Nginx的配置檔案中新增以下內容:
upstream backend { server 192.168.10.91:8999; server 192.168.10.92:8999; server 192.168.10.93:8999; server unix:/var/run/nginx/perl_cgi-dispatch.sock; }
server { listen 80; server_name localhost; root /var/www/; index index.html;
location ~ \.(pl|cgi)$ { gzip off; fastcgi_index index.cgi; include fastcgi.conf; fastcgi_read_timeout 5m; fastcgi_pass backend;
} |
這個配置是一個輪詢的實現,可以新增ip_hash指令,實現“貼上”訪問。
例子2、
在這個例子中,我們將測試快取,為了看出效果,因此我們使用了兩臺後臺伺服器,即兩臺perl-FastCGI。環境是這樣的:
前臺Nginx伺服器:
IP地址為 192.168.10.95
然後對映為外網IP,對外域名www.xx.com
後臺perl-FastCGI:
IP地址為 192.168.10.91
IP地址為 192.168.10.92
測試頁面:
IP地址為 192.168.10.91的perl-FastCGI伺服器的頁面內容為:
[root@ fastcgi1 www]# pwd /var/www [root@ fastcgi1 www]# cat test.pl #!/usr/bin/perl
print "Content-type: text/html\n\n"; print "This is 192.168.10.91."; |
IP地址為 192.168.10.91的perl-FastCGI伺服器的頁面內容為:
[root@ fastcgi2 www]# pwd /var/www [root@ fastcgi2 www]# cat test.pl #!/usr/bin/perl
print "Content-type: text/html\n\n"; print "This is 192.168.10.92."; |
在Nginx的配置檔案中新增以下內容:
http { fastcgi_cache_path /var/tmp/perl-FastCGI levels=1:2 keys_zone=CACHE:10m inactive=5m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
upstream backend { server 192.168.10.91:8999; server 192.168.10.92:8999; }
server { listen 80; server_name localhost; root /var/www/; index index.html;
location ~ \.(pl|cgi)$ { gzip off; fastcgi_index index.cgi; include fastcgi.conf; fastcgi_read_timeout 5m; fastcgi_pass backend; fastcgi_cache CACHE; fastcgi_cache_valid 200 302 1h; fastcgi_cache_valid 301 1d; fastcgi_cache_valid any 1m; fastcgi_cache_min_uses 1; fastcgi_cache_use_stale error timeout invalid_header http_500; } |
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/27043155/viewspace-732400/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Nginx和php的結合NginxPHP
- tomcat結合httpd和nginxTomcathttpdNginx
- JWS與Nginx的結合Nginx
- nginx結合fastcgiNginxAST
- Nginx通過內建的Perl模組執行Perl程式Nginx
- Nginx提供perl CGI訪問Nginx
- dockerfile構建nginx並結合phpDockerNginxPHP
- 兩個將來可能很厲害的perl 專案:perl雲端計算及跟google app engine的結合GoAPP
- windows批處理之四:特殊的字串擷取及結合perl的操作Windows字串
- Perl的包和模組
- lucene和NoSQL的結合SQL
- Perl語言學習(四)Perl控制結構
- nginx結合php實現高階配置詳解NginxPHP
- perl的包(package)和模組(PM)Package
- Perl5的包和模組
- Apache httpd和php的結合方式ApachehttpdPHP
- Program perl 資料結構資料結構
- perl DBI 學習總結
- frp與nginx結合,實現內網裝置的ssh,遠端桌面和http訪問FRPNginx內網HTTP
- tomcat結合nginx或apache做負載均衡及session繫結TomcatNginxApache負載Session
- Cultured Perl: 吸引 C 和 Java 程式設計師目光的 Perl 5.6 (轉)Java程式設計師
- [譯] TypeScript 和 Babel:美麗的結合TypeScriptBabel
- css和html的四種結合方式CSSHTML
- sed命令和find命令的結合的使用
- `GitHub page` 和 `gitbook` 結合使用Github
- springboot和mybatis結合Spring BootMyBatis
- 結合使用 Hadoop 和 CouchbaseHadoop
- Perl中有效建立Getter 和Setter的方法
- 鏈遊開發:遊戲和NFT的結合遊戲
- Git全域性忽略和Vim Session的結合GitSession
- perl Statistics::Descriptive Perl 的統計模組
- Perl指令碼執行方法小結指令碼
- 10,其他控制結構(perl筆記)筆記
- Go和JavaScript結合使用:抓取網頁中的影像連結GoJavaScript網頁
- vim 外掛:perl-support的修改和使用
- 結合Spotlight和Alfred的效率工具 - HapiGoAlfredAPIGo
- css和html的四種結合方式介紹CSSHTML
- Java鎖的邏輯(結合物件頭和ObjectMonitor)Java物件Object