从NGINX vhost

时间:2016-09-23 16:59:43

标签: nginx url-rewriting

我正在尝试从HTTPS重定向中排除特定的URL(所有流量都从HTTP重定向到HTTPS,因此我希望通过HTTP访问一个URL)。

要排除的网址:

http://www.domain.com/index.php?route=extension/something/something

我的VHOST domain.com.conf:

server{
listen      80;
listen      443 ssl;
server_name domain.com www.domain.com;
ssl         on;

if ( $scheme = "http" ) {
rewrite ^/(.*)$ https://$host/$1 permanent;
}
index index.php index.html;

root /var/www/domain.com;

    keepalive_timeout   60;
    ssl_certificate      /etc/nginx/ssl/domain.com.crt;
    ssl_certificate_key  /etc/nginx/ssl/domain.com.key;

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

location /image/data {
        autoindex on;
    }

location /upload {
        autoindex on;
        allow all;
        log_not_found off;
    }

location /admin {
        index index.php;
    }

location / {
        try_files $uri @opencart;
    }

location @opencart {
        rewrite ^/(.+)$ /index.php?_route_=$1 last;
    }

location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }
location ~* \.(xml|csv|xls)$ {
    allow all;
    log_not_found off;
}

location ~* \.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(\..*|Entries.*|Repository|Root|Tag|Template)$|\.php_ {
        deny all;
    }

location ~ /\. {
        deny all;
        access_log off;
        log_not_found off;
    }

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

我搜索了所有内容并尝试了所有提示,但没有成功。

1 个答案:

答案 0 :(得分:0)

请尝试以下代码,

server {
   ...
   set $is_redirect "0";
   if ( $scheme = "http" ) {
      set $is_redirect "1";
   }
   if ($arg_route ~* "extension/something/something") {
      set $is_redirect "0";
   }
   if ($is_redirect) {
      rewrite ^/(.*)$ https://$host/$1 permanent;
   }
   ...
}