使用子域配置nginx server-block时出现问题

时间:2013-03-09 14:50:07

标签: ubuntu nginx

我总是使用apache来获取自己的vps。最近我决定改用nginx。我之前从未使用它,所以我在找出使用子域配置虚拟主机时遇到的一些问题。

我的vps正在运行ubuntu 12.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
  • 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_html/index.php < / strong> /usr/share/nginx/blog.marano.tk/public_html/index.php

我哪里出错了?

抱歉我的英文不好

0 个答案:

没有答案