NGINX中奇怪的子域问题

时间:2015-05-30 17:56:18

标签: redirect nginx https subdomain

我想做的是:

  • 仅将www.domain.comdomain.com重定向到https://domain.com
  • subdomain.domain.comdomain.com转发到同一目录
  • backend.domain.com转发到单独的目录

要完成这项工作,我正在使用上面的配置。但它会将所有子域重定向到https://domain.com。尝试使用和不使用第二个服务器代码块(重定向块)。

我做错了什么?

server {
    ssl on;
    ssl_certificate /etc/nginx/ssl/cert_chain.crt;
    ssl_certificate_key /etc/nginx/ssl/server.key;
    charset utf-8;
    client_max_body_size 128M;

    listen 443 default ssl;

    server_name domain.com *.domain.com;
    root        /var/www/frontend/web;
    index       index.php;

    location / {
        # Redirect everything that isn't a real file to index.php
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
        try_files $uri =404;
    }
    error_page 404 /404.html;

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
        #fastcgi_pass   127.0.0.1:9000;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        try_files $uri =404;
    }

    location ~ /\.(ht|svn|git) {
        deny all;
    }
}   
server {
       listen         80;
       server_name    domain.com www.domain.com;
       return         301 https://$server_name$request_uri;
}

server {
    charset utf-8;
    client_max_body_size 128M;

    listen 80; ## listen for ipv4
    #listen [::]:80 default_server ipv6only=on; ## listen for ipv6

    server_name backend.domain.com;
    root        /var/www/backend/web;
    index       index.php;


    location / {
        # Redirect everything that isn't a real file to index.php
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
        try_files $uri =404;
    }
    #error_page 404 /404.html;

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        try_files $uri =404;
    }

    location ~ /\.(ht|svn|git) {
        deny all;
    }
}

0 个答案:

没有答案