2016-09-23 3 views
0

Я пытаюсь исключить конкретный URL из перенаправления HTTPS (весь трафик перенаправляется с HTTP на HTTPS, поэтому я хочу, чтобы один URL был доступен через HTTP).Исключая конкретный URL из перенаправления HTTPS на NGINX vhost

URL исключить:

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

Мой ВХост 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; 
    } 
} 

Я гугле все и попытался все советы здесь не увенчались успехом.

ответ

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; 
    } 
    ... 
} 
+0

Спасибо за отличное решение. У меня есть другой вопрос: как добавить rewrite для этой ситуации, чтобы также вернуть HTTP? rewrite ^/googlebase.xml $ /index.php?route=feed/google_base last; – Autreau

+0

Я думаю, что вы хотите переписать во время обработки HTTP, попробуйте, если ($ schem = "http") {переписать ^/googlebase.xml $ /index.php?route=feed/google_base last; } ниже третьего блока if. – Satys