导读 在使用PHPStudy搭建开发环境时,如果需要为多个项目配置虚拟主机,或者启用伪静态规则,可以参考以下步骤👇:首先,在PHPStudy中打开Nginx...
在使用PHPStudy搭建开发环境时,如果需要为多个项目配置虚拟主机,或者启用伪静态规则,可以参考以下步骤👇:
首先,在PHPStudy中打开Nginx的配置文件(通常位于`安装目录/conf/nginx.conf`)。找到`server`块,新增一个虚拟主机配置。例如:
```nginx
server {
listen 80;
server_name project.local;
root "D:/www/project";
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
```
记得在`hosts`文件中添加域名映射:`127.0.0.1 project.local`。
配置完成后重启Nginx服务,即可通过`project.local`访问你的项目。如果需要伪静态规则,可以直接在`location`块中添加`rewrite`指令,比如:
```nginx
rewrite ^/article-([0-9]+)\.html$ /index.php?act=article&id=$1 last;
```
这样,无论是开发还是调试,都能轻松搞定!💪
版权声明:本文由用户上传,如有侵权请联系删除!