虚拟主机的配置,一个server就代表一个虚拟主机,这里可重复设置的配置很多,建议使用include,设置多个主机的时候可以减少配置文件的代码量;
修改配置文件vim /usr/local/nginx/conf/nginx.conf
找到http{
在
server {
listen 80 default_server;
上边 插入以下代码
include /usr/local/nginx/conf.d/*.conf;
进入 cd /usr/local/nginx/conf.d/ 目录
创建文件 vim localhost.conf
内容如下:
server {
listen 3700;
server_name localhost;
error_log /var/log/nginx/localhost-error.log;#错误日志所在目录
rewrite_log on; # 开启重写规则日志
#access_log logs/host.access.log main;
root /data/web/localhost-api/web;//网站文件所在目录
location /static/ {
root /data/web/localhost-api/;
}
# location ~\.jpg|\.png|\.jpeg|\.gif|\.js|\.html|\.css$ {
# root /data/web/localhost-api/static;
# }
location /uploaded/ {
root /data/web/localhost-api/;
}
location / {
index index.php index.html index.htm;
if (!-e $request_filename){
rewrite ^/(.*) /index.php?r=$1 last;
#rewrite /index.html /index last;
}
}
location = /50x.html {
root html;
}
location ~ \.php$ {
root /data/web/localhost-api/web;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param LOCAL_ENV "localhost";//定义环境变量
include fastcgi_params;
}
}