cydooo
cydooo
2013-06-27 06:25
采纳率: 0%
浏览 628
已采纳

nginx location如何消除重复配置项?

例如有如下两个location配置
[code="java"]
location ~ /xxx/.+$ {
proxy_pass http://tomcat;
proxy_set_header Host $host;
proxy_set_header X-URI $request_uri;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-Scheme $scheme;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

location ~ /yyy/.+$ {
rewrite ^/yyy/(.+)$ /ddd?x=$1 break;
proxy_pass http://tomcat;
proxy_set_header Host $host;
proxy_set_header X-URI $request_uri;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-Scheme $scheme;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
[/code]

两个location中有很多重复配置项,这些配置项有什么办法只配置一次就能在所有location中引用?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • jinnianshilongnian
    jinnianshilongnian 2013-06-28 07:44
    已采纳

    1、在http 下加include proxy.conf
    http {
    include mime.types;
    include proxy.conf;

    2、把代理相关的配置拿过去proxy.conf
    #!nginx (-)

    proxy.conf

    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;
    client_max_body_size 10m;
    client_body_buffer_size 128k;
    proxy_connect_timeout 90;
    proxy_send_timeout 90;
    proxy_read_timeout 90;
    proxy_buffers 32 4k;

    点赞 评论

相关推荐