2016-08-02 13 views
0

Nginxは、そうしたアプリケーションサーバーのためにリバースプロキシとして設定されていますが、そこには重複したコードがたくさんあります(ただし、proxy_pass行は例外です)。 proxy_redirect行とproxy_set_header行をいくつかの共通ブロックに移動して、各ロケーションブロックに対して参照できる方法はありますか?Nginxの再利用可能なブロック

Nginx.conf:

location ^~ /users { 
      proxy_pass http://192.168.0.1:5001; 
      proxy_redirect http://api.example.com https://api.example.com; 
      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-Forwarded-Proto https; 
} 

location ^~ /users/verify { 
      proxy_pass http://192.168.0.1:5002; 
      proxy_redirect http://api.example.com https://api.example.com; 
      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-Forwarded-Proto https; 
} 

答えて

0

確かに。あなたはそのようなあなたの設定のあなたのhttpブロックでこれを行うことができます。

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"'; 

    #Rest of your config 

    #Proxy settings 
    proxy_redirect http://api.example.com https://api.example.com; 
    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-Forwarded-Proto https; 

    include /etc/nginx/conf.d/*.conf; 
} 

注これらの設定は、「グローバル」であろうと。

関連する問題