1

我正在尝试对我的网站进行重写,以便将 eosgaming.com 重写为 www.eosgaming.com。

这是我的 virtual.conf

#
# A virtual host using mix of IP-, name-, and port-based configuration
#

#server {
#    listen       8000;
#    listen       somename:8080;
#    server_name  somename  alias  another.alias;

#    location / {
#        root   html;
#        index  index.html index.htm;
#    }
#}

server {
  listen 80;
  server_name eosgaming.com;
  rewrite ^/(.*) http://www.eosgaming.com/$1 permanent;
}

server {
    listen       80;
    server_name  .eosgaming.com;

    error_log /home/web/eosgaming.com/logs/error.log;

    root   /home/web/eosgaming.com/public_html/;
    index  index.html index.htm index.php;

    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;
    server_name  .forum.eosgaming.com;

    error_log /home/web/forums.eosgaming.com/logs/error.log;

    root   /home/web/forums.eosgaming.com/public_html/;
    index  index.html index.htm index.php;

    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;
       server_name .mysql.eosgaming.com;

       error_log /home/web/mysql.eosgaming.com/logs/error.log;

       root /usr/share/phpMyAdmin;

       location / {
           index  index.php;
       }

       ## Images and static content is treated different
       location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
           access_log        off;
           expires           360d;
       }

       location ~ /\.ht {
           deny  all;
       }

       location ~ /(libraries|setup/frames|setup/libs) {
           deny all;
           return 404;
       }

       location ~ \.php$ {
           include /etc/nginx/fastcgi_params;
           fastcgi_pass 127.0.0.1:9000;
           fastcgi_index index.php;
           fastcgi_param SCRIPT_FILENAME /usr/share/phpMyAdmin$fastcgi_script_name;
       }
}

server {
    listen       80;
    server_name  .source.eosgaming.com;

    error_log /home/web/source.eosgaming.com/logs/error.log;

    root   /home/web/source.eosgaming.com/public_html/;
    index  index.html index.htm index.php;

    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;
    }
}

这是我得到的错误

[root@vd1 ~]# service nginx restart
nginx: [warn] conflicting server name "eosgaming.com" on 0.0.0.0:80, ignored
Stopping nginx:                                            [  OK  ]
Starting nginx: nginx: [warn] conflicting server name "eosgaming.com" on 0.0.0.0:80, ignored

我该如何解决这个问题?我只想让我的网站添加 www。

4

2 回答 2

1

我建议将您的前两个服务器指令组合成一个,例如:

server {
    listen       80;
    server_name  eosgaming.com; #removed the . because its not needed

    if ($host ~* ^[^.]+\.[^.]+$) { #check if the host has no subdomain
        rewrite ^(.*)$ http://www.$host$1 permanent; #Rewrite the url to include www.
    }

    error_log /home/web/eosgaming.com/logs/error.log;

    root   /home/web/eosgaming.com/public_html/;
    index  index.html index.htm index.php;

    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;
    }
}
于 2012-12-15T20:46:18.373 回答
0

as.eosgaming.com;等价于eosgaming.com *.eosgaming.com;,会与 冲突server_name eosgaming.com;

于 2012-12-15T20:19:27.777 回答