Nginx 一个服务器多域名配置 以及 访问php文件直接下载而不运行
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; 这句话起到了关键作用
这个文件中的内容为
location ~ [^/].php(/|$) { try_files $uri =404; fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_index index.php; include fastcgi.conf; }
-------------------------2017.08.18纠正---------------------------
关键的一句为: fastcgi_pass unix:/tmp/php-cig.sock
/tmp/php-cig.sock 为php-fpm的listen方式,还可以是127.0.0.1:9000,根据不同的listen判断进行配置
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。