NGINX에 대한 경험이 거의 없습니다. 노드를 실행하는 몇 가지 도커 컨테이너에 대해 역방향 프록시로 사용하려고합니다. 목표는 모든 요청이 NGINX를 통해 퍼널됩니다. 경로 (URL 경로)를 기반으로 특정 경로 인 domain.com/graphql이 NGINX를 통해 다른 도커 컨테이너로 전달됩니다. domain.com/graphql은 기본적으로 내 API 엔드 포인트입니다.Nginx가 리버스 프록시 서비스 301의
내 아약스/릴레이 클라이언트 요청의 모든 것은 Nginx의에서 (301)로 전달지고 클라이언트에서 살고있는 JS에 의해 만들어지고이 문제
요청 :
Request URL:http://domain.com/graphql
Request Method:POST
Status Code:301 Moved Permanently
Remote Address:192.168.99.100:80
Response Headers
view source
Connection:keep-alive
Content-Length:185
Content-Type:text/html
Date:Thu, 08 Sep 2016 15:14:02 GMT
Location:http://domain.com/graphql/
Server:nginx/1.11.3
Request Headers
view source
accept:*/*
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8,it;q=0.6
Cache-Control:no-cache
Connection:keep-alive
Content-Length:620
content-type:application/json
Host:nomralph.com
Origin:http://domain.com
Pragma:no-cache
Referer:http://domain.com/
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36
Nginx의 설정 :
upstream frontend {
least_conn;
server frontend:4444 weight=10 max_fails=3 fail_timeout=30s;
keepalive 64;
}
upstream graphql-upstream {
least_conn;
server graphql:3000 weight=1 max_fails=3 fail_timeout=30s;
keepalive 64;
}
server {
listen 80;
server_name domain.com www.domain.com;
root /var/www/public;
# Handle static files
location/{
proxy_pass http://frontend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_cache_bypass $http_upgrade;
}
location /graphql {
proxy_pass graphql-upstream/graphql;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_cache_bypass $http_upgrade;
}
}
어떻게 domain.com하지만 B에 만든 요청의 같은 HTTP 상태와 행동 domain.com/graphql하기 위해 만든 요청을 허용하도록 Nginx에 내 구성을 변경할 수 있습니다 e가 내 API 서버로 전달되었습니다.