2016-09-08 4 views
0

NGINXの経験はほとんどありません。私はノードを実行しているいくつかのドッカーコンテナのリバースプロキシとしてそれを使用しようとしています。目標はすべてNGINXを介して要請されます。ルート(URLパス)に基づいて、特定のルートdomain.com/graphqlがNGINX経由で別のドッカーコンテナに渡されます。 domain.com/graphqlは基本的に私のAPIエンドポイントです。リバースプロキシとしてのNginx 301の

私が持っている問題は、クライアントに住んJSによって作られて、私のAjax /リレークライアント要求のすべてが301

nginxのからの要求として渡さなっている次のとおりです。

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の中に私の設定を変更することができます私のAPIサーバーに渡されました。

答えて

関連する問題