Skip to content

Adding proxy-set-header directives to proxy-pass. #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<url>https://github.com/pallet/nginx-crate</url>
</scm>
<artifactId>nginx</artifactId>
<version>0.7.0-SNAPSHOT</version>
<version>0.7.1-SNAPSHOT</version>

<dependencies>
<dependency>
Expand Down
4 changes: 4 additions & 0 deletions resources/crate/nginx/location
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ location ~{location} {
~(when root (format "root %s;" root))
index ~(apply str (interpose " " index));
~(when proxy_pass (format "proxy_pass %s;" proxy_pass))
~(when (not (or (empty? proxy_pass) (empty? proxy_set_headers)))
(apply str (map
(fn [[n v]] (format " proxy_set_header %s %s;\n" (name n) (name v)))
proxy_set_headers)))
~(when passenger-enabled (format "passenger_enabled %s;" passenger-enabled))
~(when rails-env (format "rails_env %s;" rails-env))
}
7 changes: 5 additions & 2 deletions src/pallet/crate/nginx.clj
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
:root nil
:index ["index.html" "index.htm"]
:proxy_pass nil
:proxy_set_headers nil
:rails-env nil
:passenger-enabled nil})

Expand Down Expand Up @@ -214,8 +215,10 @@
"Enable or disable a site. Options:
:listen -- address to listen on
:server_name -- name
:locations -- locations (a seq of maps, with keys :location, :root
:index, :proxy_pass :passenger-enabled :rails-env)"
:locations -- locations (a seq of maps, with keys :location (the apparent path), :root (the actual path),
:index (name of the index file), :proxy_pass (url to pass to),
:proxy_set_headers (map of header name to header value, either symbols or strings),
:passenger-enabled :rails-env)"
[session name & {:keys [locations action] :or {action :enable} :as options}]
(let [available (format "%s/sites-available/%s" nginx-conf-dir name)
enabled (format "%s/sites-enabled/%s" nginx-conf-dir name)
Expand Down
7 changes: 5 additions & 2 deletions test/pallet/crate/nginx_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
(directory/directory "/etc/nginx/sites-enabled")
(remote-file/remote-file
"/etc/nginx/sites-enabled/mysite"
:content "server {\n listen 80;\n server_name localhost;\n\n access_log /var/log/nginx/access.log;\n\nlocation / {\n root /some/path;\n index index.html index.htm;\n \n \n \n}\n\nlocation /a {\n \n index index.html index.htm;\n proxy_pass localhost:8080;\n \n \n}\n\n}\n")
:content "server {\n listen 80;\n server_name localhost;\n\n access_log /var/log/nginx/access.log;\n\nlocation / {\n root /some/path;\n index index.html index.htm;\n \n\n \n \n}\n\nlocation /a {\n \n index index.html index.htm;\n proxy_pass localhost:8080;\n\n \n \n}\n\nlocation /b {\n \n index index.html index.htm;\n proxy_pass localhost:9090;\n proxy_set_header X-Real-IP $remote_addr;\n\n \n \n}\n\n}\n")
(file/file
"/etc/nginx/sites-available/mysite" :action :delete :force true)))
(first
Expand All @@ -26,4 +26,7 @@
(site "mysite"
:locations [{:location "/" :root "/some/path"}
{:location "/a"
:proxy_pass "localhost:8080"}]))))))
:proxy_pass "localhost:8080"}
{:location "/b"
:proxy_pass "localhost:9090"
:proxy_set_headers {:X-Real-IP "$remote_addr"}}]))))))