1

我一直将 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。我想在这台服务器上存储两个网站:

  • 博客.marano.tk
  • 马拉诺.tk

只是为了了解 nginx 的工作原理。

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

在里面/etc/nginx/sites-aviable我有两个配置文件(每个域一个):

  • 默认(指向 marano.tk)
  • 博客.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/

如果我指向blog.marano.tk重新启动 nginx 和 php 后,我仍然会得到/usr/share/nginx/marano.tk/public_html/index.php中的内容/usr/share/nginx/blog.marano.tk /public_html/index.php

我哪里错了?

对不起,我的英语不好

4

0 回答 0