1.环境,为了方便直接使用lnmp 一键安装包安装成 http://lnmp.org/install.html
安装完成后Nginx 配置在 /usr/local/nginx/conf/nginx.conf 在 /usr/local/nginx/conf 文件夹下 有一个 vhost 文件
之所以提到这个文件是因为配置中有一行 include vhost/*.conf; 表示他会引入所有 vhost 下 .conf 后缀的文件 nginx 路由可以通过这种引用进行设置
2.在 vhost 下新建一个test.conf
server
{
listen 80;
server_name test.com www.test.com;
index index.html index.htm index.php;
root /home/wwwroot/test;
include enable-php.conf;
}
server
{
listen 80;
server_name api.test.com;
index index.html index.htm index.php;
root /home/wwwroot/api;
include enable-php.conf;
}
test.com www.test.com; 会自动转到 /home/wwwroot/test 目录
api.test.com 会自动转到 /home/wwwroot/api目录
配置好之后要重启Nginx
#cd /usr/local/nginx/sbin
#./nginx -s reload
关于 访问php文件直接下载而不运行
include enable-php.conf; 这句话起到了关键作用
这个文件中的内

本文介绍了如何使用Nginx配置一个服务器处理多个域名,并重点讲解了当访问PHP文件导致直接下载的错误,指出关键配置项`include enable-php.conf;`及其内容`fastcgi_pass unix:/tmp/php-cig.sock;`对于正确运行PHP的重要性。
最低0.47元/天 解锁文章
8995





