ghkdqhrbals / portfolio

React기반 포트폴리오 페이지 프로젝트입니다.
0 stars 0 forks source link

Cannot redirect reversed proxy to client server(NGINX) #8

Open ghkdqhrbals opened 2 years ago

ghkdqhrbals commented 2 years ago

nginx/nginx.conf

user  nginx;
worker_processes  1;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;
events {                     
    worker_connections  1024;
}
http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    upstream docker-client {
        server client:3000;
    }
    server {
        listen 80;
        server_name localhost;
        ...
        location / {
            proxy_pass         http://docker-client;
                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;
        }
        ...    
}

Solution https://stackoverflow.com/questions/70010475/cant-access-sub-paths-on-nginx-react-router-behind-a-proxy

If you want to run app in locally, you should set server_name as localhost or 127.0.0.1 When nginx proxy get request in http://localhost, nginx pass it to client(docker container). At this time, client get request with http://{server_name}:{client_port}. So client react-router cannot read