当前位置:首页 » 编程语言 » 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指令,指定站点的文档根路径。

热点内容
一般网络的dns服务器是什么 发布:2024-05-06 13:02:43 浏览:152
压缩模具设计 发布:2024-05-06 13:02:04 浏览:561
逍遥模拟器如何配置网络 发布:2024-05-06 12:21:38 浏览:982
服务器如何检测硬件地址 发布:2024-05-06 12:12:35 浏览:738
服务器在线访问数由什么决定 发布:2024-05-06 11:39:15 浏览:678
途观21款哪个配置值得买 发布:2024-05-06 11:29:00 浏览:92
pythonspyder 发布:2024-05-06 11:15:53 浏览:166
线上服务器如何资源监控 发布:2024-05-06 11:15:07 浏览:299
页游脚本检测 发布:2024-05-06 11:05:05 浏览:925
七七网源码 发布:2024-05-06 10:27:36 浏览:295