nginx如何配置vhost代理php程序?
发布于 作者:苏南大叔 来源:程序如此灵动~
本篇文章内容比较简单,只是nginx
配置vhost
的php
程序。前提是:php-fpm
已经正常开机启动了,并且安装好了nginx
,具体见文末的参考文章。
conf文件
配置文件路径:/usr/local/etc/nginx/servers/<name>.conf
。
server {
listen 80;
server_name <domain>;
root <path>;
location / {
index index.php index.html index.htm;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
注意里面的端口9000,是对应于php-fpm里面设置的,两者需要保持一致。
结论
nginx的vhost配置其实很多的,这里仅仅是做个最简单的设置。如果您想查看更多nginx的相关设置,可以点击这里查看。https://newsn.net/tag/nginx/ 。
如果聪明的读者,把附近的几篇文章连起来看的话,就可以查看到:对于一个mac系统,如何配置nginx和apache共存,node和php共存,pm2和fpm共存。这其实才是苏南大叔最终的文章描述目的。
参考文章
- 《mac系统,php-fpm加入开机启动项》 https://newsn.net/say/php-fpm-autorun.html
- 《nginx及apache代理pm2启动的node程序》 https://newsn.net/say/nginx-apache-node.html
- 《apache配置vhost网站(php)》 https://newsn.net/say/apache-vhost-php.html


