在一个vps上为多个网站配置nginx

时间:2013-02-03 18:49:39

标签: nginx

我今天读了很多关于此的文章,但我无法理解我做错了什么。 我正在尝试使用一个与nginx的vps将两个网站(site1.com,site2.com)放在一起。

这是我的nginx.conf

user www-data;
worker_processes  1;

error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
    # multi_accept on;
}

http {
    include       /etc/nginx/mime.types;

    access_log  /var/log/nginx/access.log;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;
    tcp_nodelay        on;

    gzip  on;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

conf.d目录为空,并且在启用了站点的目录中有我的配置:

server {
        listen   80 default;
        root /home/site1/www;

        access_log  /home/site1/logs/nginx.access.log;

        server_name site1.com;

        location / {
                index index.php index.html index.htm;
                try_files $uri $uri/ /index.php?$args;
        }

        location ~ \.php$ {
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
        }
}

server {
        listen   80;
        root /home/site2/www;

        access_log  /home/site2/logs/nginx.access.log;

        server_name site2.com;

        location / {
                index index.php index.html index.htm;
                try_files $uri $uri/ /index.php?$args;
        }

        location ~ \.php$ {
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
        }
}

当然/ home / site1 / www和/ home / site2 / www都包含网站文件。

现在,如果我尝试打开site1.com,这很有意思:

我得到:无法打开site1.com:81错误

我做错了什么?为什么这个81端口被添加到URL?

1 个答案:

答案 0 :(得分:1)

我认为只需在site1.com的服务器中将 listen 80 更改为 listen 81