1.进入Vhosts目录下
cd /usr/local/nginx/conf/vhosts
2.编辑配置文件
vim test.conf
3.添加以下内容
server
{
listen 80;
server_name www.test.com www.rise.com www.aaa.com;
if ($host != 'www.test.com')
{
rewrite ^/(.*)$ http://www.test.com/$1 permanent;
}
index index.html index.htm index.php;
root /data/www;
access_log /tmp/access.log lizheng; ---添加一行
location ~ ,*admin\.php$ {
auth_basic "lizheng auth";
auth_basic_user_file /usr/local/nginx/conf/.htpasswd;
include fastcgi_params;
fastcgi_pass unix:/tmp/www.sock;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
access_log off;
expires 15d;
}
location ~ .*\.(js|css)$
{
access_log off;
expires 2h;
}
3.查看是否有错
/usr/local/nginx/sbin/nginx -t
4.重新加载
/etc/init.d/nginx reload