當前位置:首頁 » 編程語言 » nginxphp

nginxphp

發布時間: 2022-01-17 21:13:50

❶ nginx配置支持php

nginx本身不支持php解析,需要配合php-fpm來配置。

location~.php${
root/var/www;#指定php的根目錄
fastcgi_pass127.0.0.1:9000;#php-fpm的默認埠是9000
fastcgi_indexindex.php;
fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
includefastcgi_params;
}

centos下安裝php-fpm (php及其它組件已經安裝過的情況)

yuminstallphp-fpm

啟動php-fpm 並設置開機啟動 (centos 7)

systemctlstartphp-fpm
systemctlenablephp-fpm

❷ nginx與php怎麼結合在一起

nginx配置:

server{
#...其他location略
location~*.php${
fastcgi_pass127.0.0.1:9000;
}
}

PHP的fastcgi監聽9000埠

php-cgi -b 9000

❸ 如何nginx啟動php伺服器

安裝 PHP 和 nginx 後,無法解析 PHP 文件。
其中,PHP 和 nginx 的編譯安裝 configure 如下:
# PHP 5.3.9
./configure --prefix=/usr/local/php -- enable-fpm
# nginx 1.0.11
./configure --prefix=usr/local/nginx
# 成功安裝後,創建 php-fpm.conf 配置文件,刪除 nginx.conf 中「pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000」部分的注釋
cd /usr/local/php/etc
mv php-fpm.conf.default php-fpm.conf
vi /usr/local/nginx/conf/nginx.conf
# 刪除如下部分的注釋,保存退出

❹ nginx 瀏覽php的時候會變成下載

php的時候會變成下載:這是因為nginx沒有設置好碰到php文件時,要傳遞到後方的php解釋器。

看看你的nginx.conf配置,裡面有沒有這樣的設置:
location ~ .*\.php$ {
fastcgi_pass 127.0.0.1:9000;
}
上面的意思,就是說,碰到.php結尾的文件,傳遞給後方127.0.0.1的9000埠上。

當然啦,你的php-fpm解析器也需要正常運行,並監聽好9000埠,才能最終生效並有效處理php腳本

windows下開啟監聽的辦法,php-cgi.exe -b 127.0.0.1:9000 -c php\php.ini

❺ 如何正確配置 Nginx 和 PHP

直接貼上代碼逐行進行講解,此處貼出一個能正常啟動php腳本的最簡nginx vhost配置:

[plain] view plain
server {
listen 8011;
server_name test.cn;
location ~ \.php?.*$ {
root /share/test;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

1、第一個大括弧 server{ }:不必多說,代表一個獨立的server,

2、listen 8011:代表該server監聽8011埠

3、location ~ \.php?.*${
}:代表一個能匹配對應uri的location,用於匹配一類uri,並對所匹配的uri請求做自定義的邏輯、配置。這里的location,匹配了所有帶.php的uri請求,例如:http://192.168.244.128:8011/test.php/asdasd
http://192.168.244.128:8011/index.php等

4、root /share/test:請求資源根目錄,告訴匹配到該location下的uri到/share/teset文件夾下去尋找同名資源。

5、fastcgi_pass 127.0.0.1:9000:這行開始是本文的重點:這行代碼的意思是,將進入到該location內的uri請求看做是cgi程序,並將請求發送到9000埠,交由php-fpm處理。

6、fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
:這行配置意思是:動態添加了一行fastcgi配置,配置內容為SCRIPT_FILENAME,告知管理進程,cgi腳本名稱。由於我的nginx中只有fastcgi_params文件,沒有fastcgi.conf文件,所以要使php-fpm知道SCRIPT_FILENAME的具體值,就必須要動態的添加這行配置。

7、include fastcgi_params; 引入fastcgi配置文件

以上就是最簡潔版的nginx啟動php腳本的最簡配置,當重啟nginx之後,在/share/test目錄下創建一個xx.php文件,輸入<?php
echo "hello world"; ?>保存,然後在瀏覽器中訪問localhost:8011/xx.php
就可以在網頁上顯示hello world了。

❻ NGINX+PHP好,還是NGINX+APACHE+PHP好

如果單台伺服器的話,NGINX+APACHE+PHP
純粹多此一舉,多了一次請求轉發,效率肯定低,而且現在FPM已經足夠穩定。完全沒必要。
只有多台伺服器集群的話,apache+nginx反代才有意義.NGINX+APACHE+PHP
這種架構存在的原因除了apache出現比較早外,還因為當時FPM不如mole模式穩定。
不見得。Nginx在前面實現動靜分離,靜態內容由Nginx負責,動態請求則交給後面的PHP應用伺服器Apache(libphp5.so)處理。Apache專心處理PHP,這不挺好嗎?
Nginx+PHP-FPM相對Nginx+Apache(libphp5.so)來說,PHP-FPM更靈活,在php-fpm.conf里可以配置監聽不同埠的多個pool,每個pool又可以自由配置PHP-FPM工人進程數pm.max_children,一個pool里的工人進程繁忙不會影響到另一個pool。在Nginx里可以配置應用的不同部分使用不同的pool,而且一台伺服器上可以運行多個版本的PHP-FPM,藉助Nginx的upstream功能,PHP-FPM非常容易橫向擴展。
新浪微博和網路貼吧都在使用Nginx+PHP-FPM的架構,PHP-FPM已經足夠穩定。
ab同樣並發數壓力測試ZF下RPS(請求每秒)對比:

❼ nginx 出現.php怎麼解決

網上找了半天,沒有找到合適的解決方法,希望遇到同樣的問題的同學,解答一下
1、/etc/nginx/nginx.conf
user www-data www-data;
worker_processes 1;

error_log /home/log/nginx.log crit;
pid /var/run/nginx.pid;

worker_rlimit_nofile 51200;

events {
use epoll;
worker_connections 51200;
}

http {
include mime.types;
default_type application/octet-stream;

server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 50m;

sendfile on;
tcp_nopush on;

keepalive_timeout 60;

tcp_nodelay on;

fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 256k;

gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
#limit_zone crawler $binary_remote_addr 10m;

#log format
log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';

include vhost/*.conf;
2、/etc/nginx/vhost/default.conf
貼一下我的配置

server {
listen 80;
server_name test.com;
index index.html index.htm index.php;
root /home/www/default;

location ~ .*\.(php|php5)?$ {
try_files $uri = 404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
expires 30d;
}

location ~ .*\.(js|css)?$ {
expires 12h;
}

#error_page 404 /404.html;

#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
# root /var/www/nginx-default;
#}

access_log /home/log/default.log access;
}
~

❽ 如何正確配置Nginx+PHP

其實沒多復雜
1. 將nginx和php都裝好了
2. 然後配置nginx,將php請求分發給php-fpm處理
linux下的配置文件一般在/usr/local/nginx/conf/nginx.conf
找到下面字樣,並取消注釋,且注意這個$document_root這個地方(原本應為$script***的,改成$document_root)
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

3.啟動nginx和php-fpm,然後寫個phpinfo腳本測試下成功與否就可以了

❾ linux nginx 無法執行php文件

為以前沒有接觸過nginx ,所以查了一天,查處原因有二:
一、網站根目錄
默認是在 /usr/local/nginx/html文件
配置在
location / {
root /home/www/wwwroot;
index index.html index.htm;
}

二、修改文件中對應的php配置部分
location ~ \.php$ {
root /home/www/wwwroot;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
特別需要注意的是:fastcgi_param這個參數默認的是$fastcgi_script_name;最好改為$document_root$fastcgi_script_name;我在實際配置中出現了php找不到需要解析文件而返回404或者500錯誤的問題。所以最好是帶上網站根目錄的路徑變數$document_root

❿ nginx PHP文件不能正常訪問.

一般nginx默認配置中會是這個樣子的。這里有一個SCRIPT_FILENAME變數,但是fastcgi_params這個文件中是不包含該變數的,改變數的定義實際上是在fastcgi.conf文件中。

實際上可以把配置修改成如下的配置。

location~.php${
root/usr/share/nginx/html;
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.php;
fastcgi_intercept_errorson;
includefast_cgi.conf;

#可以增加rewrite,也可以不增加。
}

按如上的配置,如果訪問127.0.0.1:9000/a.php,則實際上根據root指令和fast_cgi.conf配置,nginx會通過fast_pass指令訪問/usr/share/nginx/html/a.php這個文件。

記得用root指令,指定站點的文檔根路徑。

熱點內容
linuxi2c設備 發布:2024-04-24 06:53:50 瀏覽:345
寶馬x5買什麼配置性價比高 發布:2024-04-24 06:45:22 瀏覽:849
最小的編程語言 發布:2024-04-24 06:44:16 瀏覽:816
自動發朋友圈腳本 發布:2024-04-24 06:40:32 瀏覽:153
最早存儲盤 發布:2024-04-24 06:39:54 瀏覽:943
編程題優惠券 發布:2024-04-24 06:29:46 瀏覽:998
在線編程招聘 發布:2024-04-24 06:23:11 瀏覽:68
svn緩存文件 發布:2024-04-24 06:09:53 瀏覽:139
現在的我的世界伺服器推薦 發布:2024-04-24 05:46:39 瀏覽:151
安卓手機怎麼調節字體顏色 發布:2024-04-24 05:43:14 瀏覽:411