Nginx和php的結合
在上面分別分析了Nginx的FastCGI模組和php的php-fpm模式,下面通過一個例子將這兩者結合起來,使得動靜分離,靜態網頁由Nginx處理,而動態網頁由php-fpm處理,其實在本章一開始的部分就將這兩者結合起來了。
新增Nginx配置
下面看一個配置例項:
Nginx配置檔案nginx.conf:
…… http { include conf/mime.types; default_type application/octet-stream; server_names_hash_bucket_size 128;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on; #tcp_nopush on;
fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 128k; fastcgi_connect_timeout 150; fastcgi_send_timeout 150; fastcgi_read_timeout 150;
#keepalive_timeout 0; keepalive_timeout 20; tcp_nodelay on;
#gzip on;
server { listen 192.168.3.12:80; server_name xxx.com www.xxx.com; #charset utf8;
#access_log logs/host.access.log main;
location = / { root /sdb1/www/; index index.php; }
location / { root /sdb1/www/; index index.php index.html;
if (!-f $request_filename) { rewrite ^(.*)$ /index.php?q=$1 last; break; }
if (!-d $request_filename) { rewrite ^(.*)$ /index.php?q=$1 last; break; }
}
error_page 404 /index.php;
# static files directly location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico)$ { access_log off; expires 30d; }
# redirect error pages to the static page /50x.html error_page 500 502 503 504 /50x.html; location = /50x.html { root html; }
location ~ .php$ { fastcgi_pass 127.0.0.1:9001; fastcgi_index index.php; include fastcgi.conf; }
# deny access to .htaccess files, if it’s a Apache's document root location ~ /\.ht { deny all; }
} } ……
|
新增php-fpm配置
php-fpm的配置檔案php-fpm.conf:
[root@mail etc]# grep -v ";" php-fpm.conf
[global] pid = run/php-fpm.pid error_log = log/php-fpm.log log_level = debug emergency_restart_threshold = 10 emergency_restart_interval = 20 process_control_timeout = 5
[www]
listen = 127.0.0.1:9000 listen.allowed_clients = 127.0.0.1 user = nobody group = nobody
pm = dynamic pm.max_children = 50 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 20 pm.max_requests = 300
pm.status_path = /status ping.path = /ping ping.response = pong
request_terminate_timeout = 50 request_slowlog_timeout = 50
slowlog = log/$pool.log.slow rlimit_files = 1024
|
還有一個FastCGI的引數檔案fastcgi.conf就不貼出來了就是上面的那個內容。然後再重新載入Nginx的配置檔案就可以了。
本例項是在一個業務不太繁忙下的配置,如果你的業務較忙,那麼根據實際情況對配置檔案中的引數做相關調整就可以了,在前面的內容中已經將配置檔案中的指令介紹過了。
有關使用upstream_keepalive模組提供FastCGI模組實現keep-live的知識請參考卷1,在此就不多羅嗦了。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/27043155/viewspace-733320/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Nginx和Perl的結合Nginx
- dockerfile構建nginx並結合phpDockerNginxPHP
- tomcat結合httpd和nginxTomcathttpdNginx
- Apache httpd和php的結合方式ApachehttpdPHP
- nginx結合php實現高階配置詳解NginxPHP
- JWS與Nginx的結合Nginx
- nginx結合fastcgiNginxAST
- MongoDB結合PHPMongoDBPHP
- httpd結合php的fpm模式httpdPHP模式
- nginx 和 PHP-fpm 的互動NginxPHP
- PHP-FPM和nginx配置PHPNginx
- Docker 搭建多容器組合服務 (nginx + PHP)DockerNginxPHP
- Nginx和php是怎麼通訊的?NginxPHP
- 配置nginx+php+MT4.2總結NginxPHP
- 原始碼安裝Nginx和PHP原始碼NginxPHP
- 如何正確配置 Nginx 和 PHPNginxPHP
- Nginx前端設定反向代理,後端Apache如何獲取訪客的真實IP,結合PHPNginx前端後端ApachePHP
- lucene和NoSQL的結合SQL
- php 和 nginx 的幾個超時時間PHPNginx
- PHP-FPM 與 Nginx 的通訊機制總結PHPNginx
- Mac下Nginx、PHP、MySQL 和 PHP-fpm安裝配置MacNginxPHPMySql
- Ubuntu 系統下部署nginx 和 php 7.2UbuntuNginxPHP
- 【Nginx】php+nginx快速搭建NginxPHP
- nginx and php and zabbixNginxPHP
- CentOS下檢視nginx和php的編譯引數CentOSNginxPHP編譯
- PHP結合Ajax實現登入驗證的DemoPHP
- saltstack之nginx、php的配置NginxPHP
- 配置nginx對php的支援NginxPHP
- Docker下安裝Nginx和php(爬坑篇)DockerNginxPHP
- frp與nginx結合,實現內網裝置的ssh,遠端桌面和http訪問FRPNginx內網HTTP
- tomcat結合nginx或apache做負載均衡及session繫結TomcatNginxApache負載Session
- PHP 結合 MySQL 千萬級資料處理PHPMySql
- Laravel 結合 Redis 實現 PHP 定時器LaravelRedisPHP定時器
- PHP-fpm + nginxPHPNginx
- nginx+php-cgiNginxPHP
- Nginx配置支援phpNginxPHP
- [譯] TypeScript 和 Babel:美麗的結合TypeScriptBabel
- css和html的四種結合方式CSSHTML