使用场景:由于特殊原因需要在一个nginx虚拟机下运行两个php网站,解决这个需求有两种方案:
第一种:是直接在原来的项目下新建一个目录然后把新站点放进去;
第二种:在外面新建一个项目然后利用nginx的location和alias 虚拟目录来实现;
第一种方案最简单 nginx都不用修改,但是如果出现安全问题,两个站点会互相影响,所以我选择了第二种.这里主要是用来做笔记就不废话了直接上代码:
server { listen 80; server_name www.32e.top; default_type text/plain; location / { root /html/32e; index index.php index.htm index.html; } location /blog { alias /html/web/blog; index index.html index.htm index.php; } location ~ ^/blog/.+\.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /html/web$fastcgi_script_name; include fastcgi_params; } location ~ \.php$ { root /html/32e; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } error_log /var/log/nginx/32e_error.log; access_log /var/log/nginx/32e_access.log main; }
注意事项:
1,注意虚拟目录的名称和实际目录名称要一致,否则php配置的时候会有问题;
好了就先到这里把不BB了,还得继续搬砖...
除特别注明外,本站所有文章均为博文家原创,转载请注明出处来自https://www.32e.top/services/linux/article-145.html
暂无评论