Ubuntu 使用子域配置nginx服务器块时出现问题

Ubuntu 使用子域配置nginx服务器块时出现问题,ubuntu,nginx,Ubuntu,Nginx,我自己的vps总是使用apache。最近我决定换用nginx。我以前从未使用过它,所以我正在研究如何使用子域配置虚拟主机 我的vps运行的是Ubuntu12.04,全新安装,没有安装apache 我想在文件夹/usr/share/nginx中存储多个网站。在这个目录中,我有以下结构: root@mauro-vps:/usr/share/nginx# tree . ├── blog.marano.tk │   └── public_html │   └── index.php └── ma

我自己的vps总是使用apache。最近我决定换用nginx。我以前从未使用过它,所以我正在研究如何使用子域配置虚拟主机

我的vps运行的是Ubuntu12.04,全新安装,没有安装apache

我想在文件夹/usr/share/nginx中存储多个网站。在这个目录中,我有以下结构:

root@mauro-vps:/usr/share/nginx# tree
.
├── blog.marano.tk
│   └── public_html
│       └── index.php
└── marano.tk
    └── public_html
        └── index.php
正如您所看到的,我已经设置了一个免费域名(marano.tk),指向我的vps的ip。我想在此服务器上存储两个网站:

  • blog.marano.tk
  • 马拉诺
只是为了了解nginx是如何工作的

我的
/etc/nginx/nginx.conf
是默认值,我没有在其中编辑任何内容

/etc/nginx/sites aviable
内部,我有两个配置文件(每个域一个):

  • 默认值(指向marano.tk)
  • blog.marano.tk
第一个文件
#/etc/nginx/sites aviable/default

    server {

        #listen   80; ## listen for ipv4; this line is default and implied
        #listen   [::]:80 default ipv6only=on; ## listen for ipv6

        #root /usr/share/nginx/www;
        root /usr/share/nginx/marano.tk/public_html;
        index index.html index.htm index.php;

        # Make site accessible from http://localhost/
        server_name marano.tk www.marano.tk;

        location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to index.html
            try_files $uri $uri/ /index.html;
            # Uncomment to enable naxsi on this location
            # include /etc/nginx/naxsi.rules
        }

        location /doc/ {
            alias /usr/share/doc/;
            autoindex on;
            allow 127.0.0.1;
            deny all;
        }

        location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

            # With php5-cgi alone
            fastcgi_pass 127.0.0.1:9000;
            # With php5-fpm;
            #  fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
        }

    }
第二个文件
/etc/nginx/sites aviable/blog.marano.tk

    server {
        #listen   80; ## listen for ipv4; this line is default and implied
        #listen   [::]:80 default ipv6only=on; ## listen for ipv6


        root /usr/share/nginx/blog.marano.tk/public_html;
        index index.html index.htm index.php;

        # Make site accessible from http://localhost/
        server_name blog.marano.tk www.blog.marano.tk;

        location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to index.html
            try_files $uri $uri/ /index.html;
            # Uncomment to enable naxsi on this location
            # include /etc/nginx/naxsi.rules
        }

        location /doc/ {
            alias /usr/share/doc/;
            autoindex on;
            allow 127.0.0.1;
            deny all;
        }


    location ~ \.php$ {
       try_files $uri =404;
       fastcgi_split_path_info ^(.+\.php)(/.+)$;
       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

        # With php5-cgi alone
        fastcgi_pass 127.0.0.1:9000;
        # With php5-fpm;
    #  fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
      } 
    }
然后我将这两个文件进行了符号链接:

ln -s /etc/nginx/sites-aviable/default /etc/nginx/sites-enabled/
ln -s /etc/nginx/sites-aviable/blog.marano.tk /etc/nginx/sites-enabled/
重新启动nginx和php后,如果我指向blog.marano.tk,我仍然会得到/usr/share/nginx/marano.tk/public\u html/index.php中的内容,而不是/usr/share/nginx/blog.marano.tk/public\u html/index.php

我错在哪里


对不起,我的英语不好

请删除php位置中的
try_files
语句,并尝试将
fastcgi_param SCRIPT_FILENAME$document_root$fastcgi_SCRIPT_name在两个配置文件中?是。我相信
try\u文件
不需要在那里,因为您将连接传递到cgi服务器。您在整个代码中使用的站点不可用,这将导致它无法工作。