0

Can't find a simple example on how to redirect all url traffic to a single website with functional links using NGINX config file. For example:

http://abcd.com -> https://www.wikipedia.org
https://defg.com -> https://www.wikipedia.org
http://uvw.com/xyz/test.html -> https://www.wikipedia.org

I tried:

server {
    listen 80;
    location / {
        proxy_pass https://www.wikipedia.org;
        }
    }

and it does direct traffic there but when I click on a link it gives an error the resulting link can't be reached. So I tried:

server {
    listen 80;
    # server_name wikipedia.org; #don't think I need this line
    location / {
        return 301 https://www.wikipedia.org$request_uri;
    }
}

and it doesn't even bring up the site but instead just that the https://www.wikipedia.org can't be reached.

Anyone know what I'm missing? Thanks

  • return 301 https://www.wikipedia.org$request_uri; sends a 301 redirect response to the browser, which then tries to load wikipedia.org. If your network prevents access to the site, this cannot be used to circumvent it. – Tero Kilkanen Dec 28 '19 at 19:53
  • Thanks @TeroKilkanen. I have no restrictions on the network. I can't get a good example of a simple way to direct all traffic (http & https) to another site. Maybe I'm structuring the config file wrong and I don't need to have a server_name. I just am not sure what might be so simple is really holding me back. – PPL Dec 28 '19 at 21:49
  • maybe because 443 is missing? – djdomi Dec 28 '19 at 22:24
  • @djdomi I'm not sure what you mean.Sorry. – PPL Dec 29 '19 at 0:42
0

Solved part of the problem. On the slight chance anyone else is running into the same issue to a simple problem, it had to do with me running the Turnkey Linux proxy server on a Virtualbox while trying to set the windows network proxy settings on the windows box that was hosting the virtual machine.

I created a couple other virtual machines under the windows host and restored my windows box to it's original (no proxy) network settings. Now the client Virtual Machine's 2 & 3 are redirecting to wikipedia (my sample sight) no matter what url I type in now that they are pointing to the Virtual Machine 1 proxy server with the following config settings:

server {
    listen 80;
    location / {
        return 301 https://www.wikipedia.org;
    }
}

This doesn't solve the problem that if I click on a link in wikipedia that lies outside the domain, the browser follows it and I don't want it to follow a link on another domain but return to the original www.wikipedia.org page.

| improve this answer | |
  • with your current config example you are redirected to its original site, as you dont proxy to this site – djdomi Dec 30 '19 at 20:10
  • @djdomi I just want the user to be redirected to wikipedia.org no matter what they type in at the client stations at their PC's in our office. I'm using wikipedia.org as an example but I want to direct all users to a single website to prevent them from accessing any other site) – PPL Dec 31 '19 at 21:09
  • if i got the point out correctly ; you want only domainA and in case the user clicks on a links which referers to domainB it should again show domainA? – djdomi Jan 1 at 0:31
  • Yes @djdomi but don't forget for a user who clicks on a link on domainA in this case www.wikipedia.org should allow the user to see the resulting page of clicking (for example: es.wikipedia.org) which is a new subdomain and the user should also be allowed to type in a search string on domainA that allows the user to send the uri attached to the domain and function correctly since it's still on the same host domain. – PPL Jan 2 at 0:08
0

my comment would be to long, please note this as a comment instead of an answer, if it helps i woukd be glad.

upstream subdom {
server "subdom.domain.example";
}
server {
    server_name subdom.domain.example;
    listen 80;
    return 301 https://$host$request_uri;
   } 
  server {
    proxy_read_timeout 3600;
    listen 443 ssl http2;
    server_name subdom.domain.example;
            location / {
                    proxy_http_version 1.1;
                    proxy_set_header Upgrade $http_upgrade;
                    proxy_set_header Connection "upgrade";
                    client_max_body_size 0;
                    proxy_connect_timeout  3600s;
                    proxy_read_timeout  3600s;
                    proxy_send_timeout  3600s;
                    send_timeout  3600s;
                    #proxy_cache             hd_cache;
                    proxy_set_header        X-Cache-Status $upstream_cache_status;
                    proxy_cache_valid       200 1w;
                    proxy_pass              https://www.wiki-pedia.org;
                    proxy_set_header        Host $http_host;
                    proxy_buffers           16 8m;
                    proxy_buffer_size       2m;
                    gzip on;
                    gzip_vary          on;
                    gzip_comp_level    9;
                    gzip_proxied       any;
   }
       ssl_certificate 
/etc/letsencrypt/live/example/fullchain.pem; # managed 
by Certbot
ssl_certificate_key 
 /etc/letsencrypt/live/example/privkey.pem; # managed 
 by Certbot
  } 

i hope the copy&paste worked.

in this example, i also use an cache which is commented out and compression, also disable it for testing

| improve this answer | |
  • Thanks @djdomi Hmmm that's definitely different than what I was expecting. What is the subdom.domain.example? What if I didn't assign this internal TurnkeyLinux Proxy Server a fully qualified domain name? Right now the host name is just reverse-proxy. I am also not sure if that is what I need. Is this setup to direct all http & https traffic to a single site? Can I do without the subdomain and server_name settings? Can it be simpler just for now then I can add settings later? – PPL Dec 31 '19 at 17:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.