nginx 转发到 php-fpm
安装软件
yum install nginx -y
yum install php-fpm -y
配置nginx
在 /etc/nginx/conf.d/default.conf 基础上直接修改,就可以作为你的应用使用:
server {
listen 80 default_server;
server_name _;
root /usr/share/nginx/html;
include /etc/nginx/default.d/*.conf;
location / {
}
#location ~ .php$ { ## 针对所有php跳转
location ~ /testapi { ## 针对testapi底下的文件跳转。
#root /var/www/html/opsxapi;
root /var/www/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
比如我们在 /var/www/html 下部署了 testapi 这个目录,其中放置了 test.php
当启动 nginx 和 php-fpm 后,可以测试
curl http://127.0.0.1/testapi/test.php
就能够请求到这页面了。
其实的原理就是,匹配到 “/testapixxxx”这个规则后,然后返回:
/var/www/html + /testapixxxx 执行的结果。