0

I want to set up a proxy by using nginx.and I want to use a remote server on internet to be my backend server, is this possible for Nginx?

i.e. both the client and the backend server are on the internet.

i the config is somewhat like the following:

server {
    listen       443 ssl;
    server_name  localhost;

    ssl_certificate      cert.pem;
    ssl_certificate_key  cert.key;

    ssl_session_cache    shared:SSL:1m;
    ssl_session_timeout  5m;

    ssl_ciphers  HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers  on;

    location / {
    proxy_pass http://www.google.com;

    #Proxy Settings     
    proxy_redirect     off;
    proxy_set_header   Host             $host;
    proxy_set_header   X-Real-IP        $remote_addr;
    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
    #proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
    proxy_max_temp_file_size 0;
    proxy_connect_timeout      90;
    proxy_send_timeout         90;
    proxy_read_timeout         90;
    proxy_buffer_size          4k;
    proxy_buffers              4 32k;
    proxy_busy_buffers_size    64k;
    proxy_temp_file_write_size 64k;
    }
Xiaoyuvax
  • 71
  • 6

1 Answers1

1

Sure

upstream your-domain.de {
            ## network
            server 8.8.8.8:80;
}
server {
    server_name your-domain2.de;
    listen 80 ;
    location / {
        proxy_pass http://your-domain.de;
}}

You can do all sorts of things like ignoring cors etc with the right params but this is the baseline

Harper04
  • 355
  • 2
  • 10
  • i had configured it like what you have typed here, but the result is that the traffic is not proxied through,only my browser get a URI redirected to the backend server(which means my browser is visiting directly the backend server through my internet connection, this is way from what i want to get) – Xiaoyuvax Jan 16 '17 at 08:18
  • I used Fiddler to watch what's happening to the request. actually there was a http 302 issued by Nginx redirecting my browser to the backend server, how come so? – Xiaoyuvax Jan 16 '17 at 08:23
  • I am sure i configured " proxy_redirect off;" – Xiaoyuvax Jan 16 '17 at 08:23
  • Weird, i think nginx isnt doing this by itself (cannt just assume that the network is reachable for the client) this post could help. it suggests that nginx is just serving the 302 from your backend. http://stackoverflow.com/questions/20254456/intercepting-backend-301-302-redirects-proxy-pass-and-rewriting-to-another-loc – Harper04 Jan 16 '17 at 09:21
  • thanks anyway. finally i found it might be a trick of the backend server,which serves a 302 through nginx(while niginx is loyally doing its work),as i didn't notice it. – Xiaoyuvax Jan 18 '17 at 12:56
  • Yes, thats what i wanted to say :) – Harper04 Jan 18 '17 at 13:06