2

Quick backstory, I used Laravel Valet to setup a local development environment. I've since containerized the application and would like to just have Nginx proxy the main port 80 traffic to the localhost:8000 port the docker container is listening at. I've tried to remove (unpark/stop) Valet. I've commented out the lines from the nginx.conf that refer to the Valet config files. Nothing seems to work though

Here is my conf:

server {
        listen   80;
        server_name  app.trucase.test paylaw.trucase.test;
        location / {
           proxy_pass http://127.0.0.0:8000;
           proxy_set_header Host $host;
           proxy_set_header X-Real-IP $remote_addr;
           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }

I can go to app.trucase.test:8000 and it all works. But without the port, Nginx just isn't proxying the traffic. What am I missing?

Nathan Loyer
  • 1,339
  • 10
  • 20
  • 1
    Is `127.0.0.0` configured as your localhost loopback address? Or should it be `127.0.0.1`? – dbf Jan 16 '23 at 21:15
  • Good catch, it should be `127.0.0.1`. Unfortunately, the behavior has not changed. I get responses from `127.0.0.1:8000`, `app.trucase.test:8000`, but nothing from either `127.0.0.1` or `app.trucase.test`. – Nathan Loyer Jan 18 '23 at 20:04
  • First of all, the `nginx.conf` should have a `http {` section which includes `.conf` files from a certain location like `usr/local/nginx/servers/*.conf`. Create a `app.trucase.test.conf` here and leave the `nginx.conf` alone. Lastly, can you replace the `listen 80` with `listen 127.0.0.1:80; listen [::]:80` and add the following two lines in `location / {`, add `proxy_http_version 1.1;` and a header `proxy_pass_request_headers on;`. – dbf Jan 19 '23 at 09:23
  • Results are the same. ```➜ nginx git:(stable) ping app.trucase.test PING app.trucase.test (127.0.0.1): 56 data bytes 64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.117 ms 64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.202 ms 64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.231 ms ^C ➜ nginx git:(stable) wget app.trucase.test --2023-01-20 12:34:43-- http://app.trucase.test/ Resolving app.trucase.test (app.trucase.test)... 127.0.0.1 Connecting to app.trucase.test (app.trucase.test)|127.0.0.1|:80... connected. HTTP request sent, awaiting response... ^C``` – Nathan Loyer Jan 20 '23 at 18:36
  • Current `server` section of `http` in conf: ```server { listen 127.0.0.1:80; listen [::]:80; server_name app.trucase.test paylaw.trucase.test; location / { proxy_pass http://127.0.0.1:8000; proxy_http_version 1.1; proxy_pass_request_headers on; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } ``` – Nathan Loyer Jan 20 '23 at 18:39
  • Why doesn't markdown work in these comment sections? The formatting is terrible. – Nathan Loyer Jan 20 '23 at 18:40
  • Yea comment section sucks. Ok that proxy should work. Could you add to your answer the following output: `nginx -V` and `nginx -V 2>&1 | tr ' ' '\n'`. – dbf Jan 20 '23 at 23:56
  • And have your tried `valet proxy trucase http://127.0.0.1:8000` and see if `http://trucase.test` hits? – dbf Jan 21 '23 at 00:06
  • Already removed Valet. I'd love to paste the results of that command but the comment character limit is too small. – Nathan Loyer Jan 22 '23 at 19:31

0 Answers0