2

My first application is running on 8080, the second application is running on 8081, The code is as follows:

server {
    listen 80;

    server_name greatwallprojects.com;

    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

    location /pingtest {
            proxy_pass http://127.0.0.1:8081;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
        }
    }

I basically see a blank page once i try to open the second location page, the homepage works fine, but http://greatwallprojects.com/pingtest loads a blank page. If the reverse proxy method has issues should i try other methods?. Can anyone point out the issue?

Rookie9
  • 57
  • 2
  • 8

1 Answers1

0

I think that should work

upstream application_1 {
    server 127.0.0.1:8080;
}

upstream application_2 {
    server 127.0.0.1:8081;
}

server {
    listen 80;

    server_name greatwallprojects.com;

    location / {
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
        proxy_pass http://application_1;
    }

    location ~* ^\/pingtest$ {
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
            proxy_pass http://application_2;
        }
    }
pixeleet
  • 81
  • 1
  • 4
  • It didn't work, nginx fails to restart, thanks for the try though. – Rookie9 May 13 '15 at 20:03
  • could you add the whole config to the problem description above so it's better testable? – pixeleet May 13 '15 at 20:09
  • I copied the code you posted and replaced my own code with it, saved the file and then on restart nginx gave error or failed to restart. Do you know how can i know where or exactly in which line is the error?, any command in Nginx which can do that?. – Rookie9 May 13 '15 at 20:12
  • okay so just `ps uax | grep nginx` and `kill` the master process by pid then start nginx and if it gives you an error, I'd like to see it. I just tested and I get no error on this conf. Oh wait, It might be that you had to start nginx as sudo because you're binding to 80. That's usually not allowed as a regular user, and so nginx restart probably won't work without sudo. – pixeleet May 13 '15 at 20:16
  • I check the error by entering the command sudo nginx -t and this is the result "upstream" directive is not allowed here in /etc/nginx/sites-enabled/default:6. – Rookie9 May 14 '15 at 05:18
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/77778/discussion-between-rookie9-and-pixeleet). – Rookie9 May 14 '15 at 07:22
  • Updated it, because the [upstream](http://nginx.org/en/docs/http/ngx_http_upstream_module.html#upstream) was in the wrong place – pixeleet May 17 '15 at 09:26