使用nginx服务器配置多个网站

本文共有1247个字,关键词:

问题:使用nginx作为服务器,现在希望在一个服务器上搭建多个网站

解决:使用nginx的配置文件,解析不同的访问域名,跳转至不同的文件夹

方法:

一、在/var/www/ 下放置两个文件夹xiao/ 和xiang/两个文件夹,这两个文件夹里面放置代码
二、配置nginx的配置文件,找到nginx目录下的conf文件夹下的vhosts文件夹(阿里云镜像里是有现成的vhosts文件夹,没有就自己新建)
三、复制vhosts文件夹内的default.conf文件:cp -p default.conf xiang.conf
四、修改xiang.conf(如果不存在default.conf,就直接复制下面代码)

server {
    listen       80;
    server_name  xiang.com www.xiang.com;
    index index.html index.htm index.php;
    root /var/www/xiang;
    location ~ .*.(php|php5)?$
    {
        #fastcgi_pass  unix:/tmp/php-cgi.sock;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi.conf;
    }
    location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
    {
        expires 30d;
    }
    location ~ .*.(js|css)?$
    {
        expires 1h;
    }
    access_log  /alidata/log/nginx/access/xiang.log;
    error_page 404  /404.html;                       
    # 这是nginx的404页面设置,要想生效,需要在nginx.conf的http下面添加fastcgi_intercept_errors on;
}

五、重启nginx

/etc/init.d/nginx restart

参考:

http://www.server110.com/nginx/201309/981.html
版权声明:本文为作者原创,如需转载须联系作者本人同意,未经作者本人同意不得擅自转载。
添加新评论
暂无评论