../sites-enabled/domain1.co.uk

../sites-enabled/domain1.co.uk

我在一台运行 LEMP 的服务器上设置了两个域。

当我访问 domain2.co.uk 时一切正常。但当我访问 www.domain2.co.uk 时,它会重定向到 www.domain1.co.uk

nginx.conf

    user www-data www-data;
    worker_processes  4;
    events {
        worker_connections  1024;
    }
    http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        tcp_nopush      on;
        tcp_nodelay     off;
        keepalive_timeout  5;
        gzip  on;
        gzip_comp_level 2;
        gzip_proxied any;
        gzip_types      text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
        include /usr/local/nginx/sites-enabled/*;
    }

../sites-enabled/domain1.co.uk

server {
            listen   80;
            server_name  www.domain1.co.uk;
            rewrite ^/(.*) http://domain1.co.uk/$1 permanent;
       }
server {
            listen   80;
            server_name domain1.co.uk;
            access_log /home/me/public_html/domain1.co.uk/log/access.log;
            error_log /home/me/public_html/domain1.co.uk/log/error.log;
            location /  {
                        root   /home/me/public_html/domain1.co.uk/public/;
                        index  index.php index.html;
                        # WordPress supercache &  permalinks.
                        include /usr/local/nginx/conf/wordpress_params.super_cache;
                        }
            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            location ~ \.php$
                    {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            include /usr/local/nginx/conf/fastcgi_params;
            fastcgi_param SCRIPT_FILENAME /home/me/public_html/domain1.co.uk/public/$fastcgi_script_name;
                        }
       }

../sites-enabled/domain2.co.uk

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

            listen 80;
            server_name domain2.co.uk;

            access_log /home/me/public_html/domain2.co.uk/log/access.log;
            error_log /home/me/public_html/domain2.co.uk/log/error.log;

            location /
            {

                root   /home/me/public_html/domain2.co.uk/public/;
                index  index.php index.html;

                # Basic version of WordPress parameters, supporting nice permalinks.
                # include /usr/local/nginx/conf/wordpress_params.regular;
                # Advanced version of WordPress parameters supporting nice permalinks and WP Super Cache plugin
                include /usr/local/nginx/conf/wordpress_params.super_cache;
            }

            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            #
            location ~ \.php$ {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            include /usr/local/nginx/conf/fastcgi_params;
            fastcgi_param SCRIPT_FILENAME /home/me/public_html/domain2/public/$fastcgi_script_name;
            }
      }

答案1

确保使用 curl -I 而不是浏览器来测试重定向。如果您以前遇到过问题,浏览器可能缓存了错误的 301,有时在服务器配置更正后很长时间,它们仍会继续使用该缓存的 301。

相关内容