Created
July 14, 2016 11:04
-
-
Save freaker2k7/619299f5d650f4ab3f01f0c0a84629bc to your computer and use it in GitHub Desktop.
Nginx - loop Bug, I want to leave the address as is when it reaches the but
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
location ~ ^/bot/(.*)$ { | |
# root / | |
set $var1 $1; | |
proxy_pass http://127.0.0.1:8080; | |
proxy_http_version 1.1; | |
# proxy_set_header Upgrade $http_upgrade; # allow websockets | |
proxy_set_header Connection $connection_upgrade; | |
proxy_set_header X-Forwarded-For $remote_addr; # preserve client IP | |
set $test_bot 0; | |
if ($http_user_agent ~* "googlebot|yahoo|bingbot|baiduspider|yandex|yeti|slackbot|yodaobot|gigabot|ia_archiver|facebookexternalhit|twitterbot|developers\.google\.com") { | |
set $test_bot 1; | |
} | |
if ($test_bot = 0) { | |
rewrite ^/bot/(.*)$ https://homzit.com/$var1? break; | |
} | |
} | |
location / { | |
proxy_pass http://127.0.0.1:8080; | |
proxy_http_version 1.1; | |
proxy_set_header Upgrade $http_upgrade; # allow websockets | |
proxy_set_header Connection $connection_upgrade; | |
proxy_set_header X-Forwarded-For $remote_addr; # preserve client IP | |
# redirect www | |
if ($host != "homzit.com") { | |
rewrite ^ https://homzit.com$request_uri? permanent; | |
} | |
set $test_ua 0; | |
if ($http_user_agent ~* "googlebot|yahoo|bingbot|baiduspider|yandex|yeti|slackbot|yodaobot|gigabot|ia_archiver|facebookexternalhit|twitterbot|developers\.google\.com") { | |
set $test_ua 1; | |
} | |
if ($uri ~* "^/bot") { | |
set $test_ua 1; | |
} | |
if ($test_ua = 1) { | |
return 302 https://homzit.com/bot$request_uri?; | |
} | |
# this setting allows the browser to cache the application in a way compatible with Meteor | |
# on every applicaiton update the name of CSS and JS file is different, so they can be cache infinitely (here: 30 days) | |
# the root path (/) MUST NOT be cached | |
if ($uri != '/') { | |
expires 30d; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment