From d5a3a85e9acf2f1285f740208e2649b72cd483c7 Mon Sep 17 00:00:00 2001 From: Adrian Heine Date: Thu, 16 Mar 2017 10:21:17 +0100 Subject: [PATCH] Make proxy in nginx server optional --- src/symbols/nginx/server.rs | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/symbols/nginx/server.rs b/src/symbols/nginx/server.rs index 739f018..2e0e3e7 100644 --- a/src/symbols/nginx/server.rs +++ b/src/symbols/nginx/server.rs @@ -49,7 +49,7 @@ pub struct NginxServer<'a, C> where C: Deref { use std::borrow::Cow; impl<'a> NginxServer<'a, String> { - pub fn new(socket_path: &'a str, domain: &'a str, static_path: &'a str, redir_domains: &[&'a str], command_runner: &'a CommandRunner) -> Self { + pub fn new(socket_path: Option<&'a str>, domain: &'a str, static_path: &'a str, redir_domains: &[&'a str], command_runner: &'a CommandRunner) -> Self { let file_path: Cow = Cow::from(String::from("/etc/nginx/sites-enabled/") + domain); let redir_content = redir_domains.iter().map(|redir_domain| format!("server {{ @@ -60,7 +60,20 @@ impl<'a> NginxServer<'a, String> { }} ", redir_domain, domain)).fold(String::new(), |s, v| s + &v); - let content = String::from(redir_content) + &format!("server {{ + + let proxy_content = if let Some(socket) = socket_path { + format!("location / {{ + try_files $uri @proxy; +}} + +location @proxy {{ + include fastcgi_params; + proxy_pass http://unix:{}:; + proxy_redirect off; +}}", socket) + } else { "".to_string() }; + + let content = String::from(redir_content) + &format!("server {{ listen 80; # listen 443 ssl; # ssl_certificate /etc/ssl/.crt; @@ -68,17 +81,8 @@ impl<'a> NginxServer<'a, String> { server_name {}; root {}; - - location / {{ - try_files $uri @proxy; - }} - - location @proxy {{ - include fastcgi_params; - proxy_pass http://unix:{}:; - proxy_redirect off; - }} -}}", domain, static_path, socket_path); + {} +}}", domain, static_path, proxy_content); NginxServer { command_runner: command_runner, file: FileSymbol::new(file_path, content)