日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

nginx+php

發布時間:2023/12/6 php 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 nginx+php 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

nginx+php基礎架構



生產實踐

  • nginx配置文件:

  • 主配置文件

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 [root@linux-node1?conf.d]#?cat?/etc/nginx/nginx.conf user?nginx; worker_processes?auto; error_log?/var/log/nginx/error.log; pid?/run/nginx.pid; #?Load?dynamic?modules.?See?/usr/share/nginx/README.dynamic. include?/usr/share/nginx/modules/*.conf; events?{ ????worker_connections?1024; } http?{ ????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??/var/log/nginx/access.log??main; ????sendfile????????????on; ????tcp_nopush??????????on; ????tcp_nodelay?????????on; ????keepalive_timeout???65; ????types_hash_max_size?2048; ????include?????????????/etc/nginx/mime.types; ????default_type????????application/octet-stream; ????include?/etc/nginx/conf.d/*.conf; ????} [root@linux-node1?conf.d]#

    include配置文件

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 [root@linux-node1?conf.d]#?cat?bbs.conf? server?{ ????????listen???????80; ????????server_name??bbs.sense.com; ????????access_log??/tmp/bbs.log??main; ????????location?/?{ ????????????root???/www/bbs; ????????????index??index.html?index.htm; ????????} ????????location?~?.*\.(php|php5)?$?{ ????????????root?/www/bbs; ????????????fastcgi_pass??192.168.56.14:9000;?? ????????????fastcgi_index?index.php; ????????????include?fastcgi.conf; ????????} ????} [root@linux-node1?conf.d]#?cat??www.conf? server?{ ????????listen???????80; ????????server_name?www.sense.com; ????????access_log??/tmp/www.log??main; ????????location?/?{ ????????????root???/www/www; ????????????index??index.html?index.htm; ????????} ????????location?~?.*\.(php|php5)?$?{ ????????????root?/www/www; ????????????fastcgi_pass??192.168.56.12:9000; ????????????fastcgi_index?index.php; ????????????include?fastcgi.conf; ????????} ????} [root@linux-node1?conf.d]#

    2.后臺php需要開啟900端口,也就是說要編譯或者安裝php,php的監聽的地址修改為本機的ip地址,不能在是127.0.0.1了 否則nginx無法代理

    3.nginx每個項目代碼需要保存一份,php后臺每個項目需要保存一份,代碼目錄要一致

    靜態的html用戶請求 請求的是nginx上面的代碼,動態的請求,請求的php服務器上面的代碼

    舉一個簡單的例子:bbs.sense.com 的代碼在nginx上面/www/bbs 下保存一份,也得在php所在的服務器上面的/www/bbs 下面保存一份,靜態的請求請求nginx服務器的代碼,動態的請求請求php服務器的代碼


    上面基礎架構存在問題:nginx單點? php單點? nginx單點可以用keepalived解決,但是php單點必須得增加后端服務器,如果增加后端的服務器,那么nginx應該怎么配置呢



    第二種架構

    nginx主配置文件

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 [root@linux-node1?www]#?cat?/etc/nginx/nginx.conf user?nginx; worker_processes?auto; error_log?/var/log/nginx/error.log; pid?/run/nginx.pid; #?Load?dynamic?modules.?See?/usr/share/nginx/README.dynamic. include?/usr/share/nginx/modules/*.conf; events?{ ????worker_connections?1024; } http?{ ????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??/var/log/nginx/access.log??main; ????sendfile????????????on; ????tcp_nopush??????????on; ????tcp_nodelay?????????on; ????keepalive_timeout???65; ????types_hash_max_size?2048; ????include?????????????/etc/nginx/mime.types; ????default_type????????application/octet-stream; ?????upstream??fastcgiserver?{ ?????server?192.168.56.12:9000;??##此時是同一代碼 ?????server?192.168.56.14:9000;??##此時是同一代碼 ???} ????include?/etc/nginx/conf.d/*.conf; ????} [root@linux-node1?www]#

    nginx include配置文件

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 [root@linux-node1?conf.d]#?cat?www.conf? server?{ ????????listen???????80; ????????server_name?www.sense.com; ????????access_log??/tmp/www.log??main; ????????location?/?{ ????????????root???/www/www; ????????????index??index.html?index.htm; ????????} ????????location?~?.*\.(php|php5)?$?{ ????????????root?/www/www; ????????????fastcgi_pass??fastcgiserver;??#此處有修改 ????????????fastcgi_index?index.php; ????????????include?fastcgi.conf; ????????} ????} [root@linux-node1?conf.d]#

    這樣做是輪詢的方式從后端的php日志依然能夠得出來,靜態文件還是請求nginx動態文件還是請求php服務器,nginx和后端的php服務器組依然要部署和nginx相同路徑的代碼










    本文轉自 小小三郎1 51CTO博客,原文鏈接:http://blog.51cto.com/wsxxsl/1975109,如需轉載請自行聯系原作者

    總結

    以上是生活随笔為你收集整理的nginx+php的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。