Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to redirect requests on IP to domain
    text
    copied!<p>Every once in a while someone is trying to access our website through the public ip instead of one of our domains (yes we have multiple country specific domains .dk, .it, .es etc. however we also have .com as the "general"). </p> <p>Now I would like to redirect those requests coming in on the IP-adress to our www.domain.com domain instead. How would I do that in nginx without touching anything BUT requests going directly to the IP?</p> <p>Here is my nginx.conf</p> <pre><code>upstream unicorn { server unix:/tmp/unicorn.mysite.sock fail_timeout=0; } server { listen 80 default deferred; root /home/deployer/apps/mysite/current/public; proxy_set_header X-Request-Start "t=${msec}"; if (-f $document_root/system/maintenance.html) { return 503; } error_page 503 @maintenance; location @maintenance { rewrite ^(.*)$ /system/maintenance.html last; break; } location ~ ^/assets/ { gzip_static on; expires max; add_header Cache-Control public; } try_files $uri/index.html $uri @unicorn; location @unicorn { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://unicorn; } error_page 500 502 503 504 /500.html; client_max_body_size 4G; keepalive_timeout 10; } </code></pre> <p>So the question would be, how do I modify this to redirect e.g. <code>http://123.123.123.123/some_page</code> to <code>http://www.mysite.com/some_page</code> but leave all other like <code>http://www.mysite.dk/some_page</code>unchanged?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload