1、首先假设我们的项目在 /home/wwwroot/default/bathroom (bathroom 就是我们的框架项目)
具体过程如下:
1、cd /usr/local/nginx/conf/vhost 目录下
2、vim example1.com.conf 创建一个文件并把以下内容拷贝进去 ↓:
server { listen 80; server_name example1.com www. example1.com; #域名名称 以及二级虚拟域名 #access_log /www/access_ example1.log main; #访问记录日志存储位置 location / { root /www/example1.com; # 例如:root /home/wwwroot/default/Bathroom (因为make安装的lnmp环境,默认项目根路径在/home/wwwroot/default/下访问) index index.php index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 location ~ .php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /www/example1.com/$fastcgi_script_name; #这里需要改成/home/wwwroot/default/Bathroom/ (项目根目录) include fastcgi_params; } location ~ /.ht { deny all; } }
注意:可能你会想虚拟域名不是配置在nginx文件中吗。为什么会配置vhost下面
你可以 vim /user/local/nginx/conf/nginx.conf 配置文件
找到:,这里默认引入 vhost 下所有的文件,所以更方便管理
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
我的案例:
server { listen 80; server_name www.bathroomstation.com; #access_log /www/access_ example1.log main;
location / { root /home/wwwroot/default/Bathroom; index index.php index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
# location ~ .php$ { $的意思是默认以.php文件结尾 location ~ .php(.*) {
fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; # 配置pathinfo模式,访问不在出现404 fastcgi_param PATH_INFO $1; fastcgi_param SCRIPT_FILENAME /home/wwwroot/default/Bathroom/$fastcgi_script_name; include fastcgi_params; } location ~ /.ht { deny all; } }