nginx怎么配置php
1. nginx 怎么修改php配置
####nginx配置虚拟机,此配置是支持tp框架pathinfo路径的
server{
#监听端口
listen 80;
#网站域名
server_name web.api55.com;
#默认索引页
index index.php;
#网站目录
root /usr/local/nginx/html/api55;
location ~ .+\.php($|/) {
set $script $uri;
set $path_info "/";
if ($uri ~ "^(.+\.php)(/.+)") {
set $script $1;
set $path_info $2;
}
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php?IF_REWRITE=1;
include fastcgi.conf;
fastcgi_param PATH_INFO $path_info;
fastcgi_param SCRIPT_FILENAME $document_root/$script;
fastcgi_param SCRIPT_NAME $script;
}
}
####负载均衡服务配置
upstream web{
server 192.168.67.135 weight=1 max_fails=3 fail_timeout=20s;
server 192.168.67.136 weight=1 max_fails=3 fail_timeout=20s;
}
####删除原来web.api53.com里的server段里的location段,增加这一段location
location /{
proxy_pass http://web;
}
###################nginx转发php文件给apache
# 动态文件.php请求转发给后端Apache
location ~ .php$ {
# 向后端服务器发起请求时添加指定的header头信息
proxy_set_header Host $http_host;
# 向后端服务器发送真实 IP
proxy_set_header X-Real-IP $remote_addr;
# 让后端如php能直接通过变量获取真实IP
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8080;
}
# nginx找不到文件时,转发请求给后端Apache
location @proxy {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8080;
}
2. 如何正确配置 Nginx 和 PHP
php用php-fpm启动,然后nginx
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}很简单吧,如果你想学习关于php的话,可以在有空时在后盾人看看教材视频,多看看,不就会了。
3. 如何在linux下配置nginx支持php
需要。
如果是nginx+php配置,也可以通过查找php执行路径
ps
aux
|
grep
php
如,路径为
/usr/local/nginx/sbin/php-fpm
然后执行以下命令
/usr/local/nginx/sbin/php-fpm
-i
|
grep
“Loaded
Configuration
File”
即可看到php加载的配置文件
4. 如何正确配置 Nginx + PHP
1. php用php-fpm启动,然后nginx
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
这样就可以了
2.安装一个集成的软件phpstudy