2

I have an application hosted in Google App Engine. I want to use Nginx as a reverse proxy.

The proxy_pass already works, but it rewrites the URL (e.g. hitting 34.34.34.34 in the address bar redirects to sample-domain-dot-project.appspot.com AND rewrites the URL), which is something I want to avoid.

Previous solutions, already working in production (AWS servers), consisted of applying the Host header.

proxy_set_header Host $host;

However, in Google App Engine, this setting alone makes the redirect not working anymore, returning Google's 404 error page.

sites-enabled/sample.com.br

server {
    listen 80;
    client_max_body_size 1000M;

    location / {
        proxy_pass_request_headers on;
        proxy_set_header Host $host;
        proxy_pass https://sample-domain-dot-project.appspot.com;
    }
}
  • 1
    I followed the [quicktutorial](https://cloud.google.com/appengine/docs/flexible/custom-runtimes/quickstart) for the custom runtime in GAE flex and your configuration. I didn't get a 404 error. Could you provide more information about your use case? Are you using GAE standard or flexible? What runtime? Could you provide the whole configuration of your application(app.yaml, Dockerfile, etc)? – tzovourn Dec 23 '19 at 15:38
  • Sory for the delay. I actually managed yesterday to make it work. The problem was that I was using the IP as the server_name, which was strange, because when our software was in AWS, we didn't have this issue. – Patrícia Villela Dec 28 '19 at 20:41

1 Answers1

3

I solved it by creating a DNS and providing it using the server_name directive in the conf. For some reason, GCloud does not allow using the IP in the Host header, something I never had any problem using AWS services.

  • 2
    i think the reason for this is that google decided to choose the services via hostname? – djdomi Dec 28 '19 at 21:57
  • I don't know the bottom of it, unfortunately. It's a good hypothesis, though. – Patrícia Villela Dec 28 '19 at 22:06
  • for me is it clear in case they use a shared ip (i. e. my server has even only 1 main ip for round about 25 domains) – djdomi Dec 28 '19 at 22:41
  • @Patrick Villela, I'm not really sure I understand what your final config looks like (and regarding the DNS, did you create one on google cloud ?), coud your provide more details ? – Cyril Duchon-Doris Aug 04 '20 at 10:13
  • @CyrilDuchon-Doris sorry about that. Unfortunately, it's been a while, but from what I remember, I used to only have the IP address on the server_name directive when I was using AWS, because only internally would we use this machine. GCloud, it seems, do not allow it, requiring every configuration to use the domain name. So what I did was, instead of "server_name x.x.x.x", I had to use "server_name domain.com". I'm not sure (I was not the one creating it), but the DNS was probably created in GCloud as well, for our old one was in AWS. – Patrícia Villela Aug 05 '20 at 13:41
  • Thanks, I was able to solve my problem. It turns out I had simply forgotten to register my custom DNS name inside Google Cloud =_= (https://console.cloud.google.com/appengine/settings/domains). after doing this correctly, then yes, just adding the domain into server_name was enough, and my nginx reverse proxy is working like a charm now :-) – Cyril Duchon-Doris Aug 05 '20 at 14:40