Basically, I have a NGINX container and i'm trying to redirect a request made to it to a standard php server php -S localhost:8000
( that is outside the container ). I've done a research and apparently I had to use host.docker.internal, which itself points to 172.17.0.1 as its the bridge network gateway. I'm new to both NGINX and docker, can you guys help me on where my configuration is flawed? Already tried to change the value of "host-gateway" to my private IP, to my public IP, to 172.17.0.1 and nothing seems to work!
I want the request made to localhost:80 ( which docker nginx is listening ) to redirect the request to localhost:8080 ( working fine ) and then redirecting again to localhost:8000 ( get a 502 bad gateway error )
Here's my configs:
docker-compose.yml
version: '3'
services:
server:
image: nginx
ports:
- "80:80"
- "8080:8080"
volumes:
- ./default.conf:/etc/nginx/conf.d/default.conf
- ./custom.conf:/etc/nginx/conf.d/custom.conf
extra_hosts:
- "host.docker.internal:host-gateway"
default.conf
server {
listen 80;
listen [::]:80;
server_name localhost;
location / {
proxy_pass http://localhost:8080;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
custom.conf
server {
listen 8080;
server_name localhost;
location / {
root /var/home/html;
index index.html;
}
location ~ \.php$ {
proxy_pass http://host.docker.internal:8000;
}
error_page 404 400 401 /error.html;
}
nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}