Nginx仅重定向到一个域

时间:2016-01-27 14:40:54

标签: redirect nginx ftp debian

我在重新安装Debian之前备份了Nginx vhosts配置文件。当我把它们重新发送到服务器时,它只重定向到一个网站,我不知道问题出在哪里,因为之前一切运行良好,我保留了相同的配置文件。他们在这里:

Nginx.conf:

user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
worker_connections 768;
# multi_accept on;
}

http {

##
# Security Settings
##

server_tokens off;
add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";

#add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://ssl.google-analytics.com https://assets.zendesk.com https://connect.facebook.net; img-src 'self' https://ssl.google-analytics.com https://s-static.ak.facebook.com https://assets.zendesk.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com https://assets.zendesk.com; font-src 'self' https://themes.googleusercontent.com; frame-src https://assets.zendesk.com https://www.facebook.com https://s-static.ak.facebook.com https://tautt.zendesk.com; object-src 'none'";


##
# Basic Settings
##

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;

# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;

##
# SSL Settings
##

ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;

##
# Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

##
# Gzip Settings
##

gzip on;
gzip_disable "msie6";

gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

##
# Virtual Host Configs
##

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}


#mail {
#   # See sample authentication script at:
#   # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
#   # auth_http localhost/auth.php;
#   # pop3_capabilities "TOP" "USER";
#   # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
#   server {
#       listen     localhost:110;
#       protocol   pop3;
#       proxy      on;
#   }
#
#   server {
#       listen     localhost:143;
#       protocol   imap;
#       proxy      on;
#   }
#}

Website1 conf:

server {
    server_name website1.com;
    rewrite ^/(.*)$ http://www.website1.com/$1 permanent;
}
server {
    listen   80;
    root /opt/http/nginx/sites/website1/www;
    index index.php index.html;
    server_name www.website1.com;

    location / {
        try_files $uri $uri/ /index.php;
    }

    location ~*  \.(jpg|jpeg|png|gif|ico|css|js)$ {
        expires 365d;
    }

    location ~*  \.(pdf)$ {
        expires 30d;
    }

    location /blog/post/ {
        rewrite ^/blog/post/([\w-]+)-(\d+)$ /blog/post.php?url=$1&id=$2;
    }

    client_max_body_size 3M;

    error_page 403 /index.php;

    # pass the PHP scripts to FastCGI server listening on /var/run/php5-fpm.sock
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

   # gzip on;
   # gzip_min_length  1100;
   # gzip_buffers  4 32k;
   # gzip_types    text/plain application/x-javascript text/xml text/css;
   # gzip_vary on;

    access_log   /var/log/nginx/www.website1.access.log;
    error_log   /var/log/nginx/www.website1.error.log;
}

和website2 conf(上面的名称除外):

server {
    server_name website2.com;
    rewrite ^/(.*)$ http://www.website2.com/$1 permanent;
}
server {
    listen   80;
    root /opt/http/nginx/sites/website2/www;
    index index.php index.html;
    server_name www.website2.com;

    location / {
        try_files $uri $uri/ /index.php;
    }

    location ~*  \.(jpg|jpeg|png|gif|ico|css|js)$ {
        expires 365d;
    }

    location ~*  \.(pdf)$ {
        expires 30d;
    }

    client_max_body_size 3M;

    error_page 403 /index.php;

    # pass the PHP scripts to FastCGI server listening on /var/run/php5-fpm.sock
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

   # gzip on;
   # gzip_min_length  1100;
   # gzip_buffers  4 32k;
   # gzip_types    text/plain application/x-javascript text/xml text/css;
   # gzip_vary on;

    access_log   /var/log/nginx/www.website2.access.log;
    error_log   /var/log/nginx/www.website2.error.log;
}

因此,当我尝试访问website2.com时,它会将我重定向到website1.com(总是使用' www'因为我想要它)。但我不明白它可能来自哪里。

0 个答案:

没有答案