Nginx 多域名

Nginx 多域名

我正在尝试向 nginx 添加第二个虚拟主机。当我转到新域时,它会重定向到旧域。我尝试重新启动 Nginx,重新启动服务器。

有人遇到过这种情况吗,愿意分享吗?

文件: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

尝试从 fastcgi_param SCRIPT_FILENAME 中删除多余的斜杠,因此该行将是:

 /home/me/public_html/domain2/public$fastcgi_script_name;

答案2

我将 index.php 页面放在我的目录中并通过浏览器访问它。没有发生重定向。因此,似乎如果 nginx 找不到它要查找的内容,它就会重定向到另一个域。

相关内容