我可以在我的域和子域上访问我的子域URL路径吗?

时间:2014-02-15 11:24:56

标签: linux ubuntu nginx dns vps

我有一台运行nginx的DigitalOcean VPS,上面有两个网站。其上的两个网站是:www.ingledow.co.ukblog.ingledow.co.uk

我的主要(www.)域名主要是静态网站,但我的博客(blog.)子域名在Ghost上运行。

除了可以从www.blog.访问我的博客之外,一切都很完美。例如,以下是http://blog.ingledow.co.uk/puma-social-club/上的博文,但可以从http://www.ingledow.co.uk/puma-social-club/看到相同的博文。

需要注意的另一点是,如果您尝试在没有www.blog. 404s的情况下转到http://ingledow.co.uk/puma-social-club/

问题在于在同一个VPS上有两个站点,但不确定我的nginx配置是否有问题,或者我的DNS是否有问题,或两者都有问题?

nginx配置文件位于/ sites-available /并且符号链接到/ sites-enabled /

我需要修复此问题,因为它会导致Google搜索结果和搜索引擎优化问题。

这是我的DNS:

DNS

blog.ingledow.co.uk.conf

# blog.ingledow.co.uk running on Ghost

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

    root /var/www/ghost;
    index index.php index.html index.htm;

    # Make site accessible from http://localhost/
    server_name blog.ingledow.co.uk;

    location / {
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
                proxy_redirect off;
                proxy_pass http://127.0.0.1:2369;
        client_max_body_size 10m;
                break;
        }

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

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location /phpmyadmin { index index.php; }
}

ingledow.co.uk.conf

# ingledow.co.uk.conf

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

    root /var/www/ingledow.co.uk/public_html;
    index index.php index.html index.htm;

    # Make site accessible from http://localhost/
    server_name ingledow.co.uk;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to index.html
        try_files $uri $uri/ /index.html /index.php;
        # 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;
    }

    # Only for nginx-naxsi : process denied requests
    #location /RequestDenied {
        # For example, return an error code
        #return 418;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location /phpmyadmin { index index.php; }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #   deny all;
    #}
}

1 个答案:

答案 0 :(得分:1)

尝试在ingledow.co.uk服务器块中将www.添加到sever_name ingledow.co.uk;。例如:

server_name www.ingledow.co.uk ingledow.co.uk;

如果您不想在没有www的情况下访问网站。子域名前缀应该从server_name中删除。

另一种方法是让服务器块与博客一样,只需使用catch all server block作为主静态站点。