nginx+PHP的多域名配置

有朋友问如何配置nginx,支持多个域名。就有了这篇文章。

如何安装nginx+php见这里:http://blog.it580.com/nginx-php-fpm-mysql%E5%AE%89%E8%A3%85debian-squeeze-vps

1.新建配置文件

nano /etc/nginx/sites-available/test.com

2.配置内容

该配置为配置支持test.com
访问日志为/var/log/nginx/test.com.access.log
错误日志为/var/log/nginx/test.com.error.log
网站主目录为/var/www/test(注意php解析部分也要修改)

如果不是部署wordpress,删除wordpress rewrite start  到 wordpress rewrite stop的内容。

server
{
    server_name .test.com;
    access_log /var/log/nginx/test.com.access.log;
    error_log /var/log/nginx/test.com.error.log;
    root /var/www/test;
    index index.php index.html index.htm;
 
    #wordpress rewrite start
    #
    # unless the request is for a valid file, send to bootstrap
    if (!-e $request_filename)
    {
        rewrite ^(.+)$ /index.php?q=$1 last;
    }
 
    # catch all
    error_page 404 /index.php;

    #
    #wordress rewrite stop
 
    # use fastcgi for all php files
    location ~ \.php$
    {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /var/www/test$fastcgi_script_name;
        include fastcgi_params;
    }
 
        #jpg jpeg gif png css ico js swf files expires 30 day.
    location ~ \.(jpg|jpeg|gif|png|css|ico|js|swf)$ {
                access_log off;
                expires 30d;
        }

    # deny access to apache .htaccess files
    location ~ /\.ht
    {
        deny all;
    }
}

3.链接配置

cd /etc/nginx/sites-enabled

ln -s /etc/nginx/sites-available/test.com

4.应用配置

/etc/init.d/nginx restart

发表评论

电子邮件地址不会被公开。 必填项已用*标注