Browse Source

Make proxy in nginx server optional

master
Adrian Heine 8 years ago
parent
commit
d5a3a85e9a
  1. 28
      src/symbols/nginx/server.rs

28
src/symbols/nginx/server.rs

@ -49,7 +49,7 @@ pub struct NginxServer<'a, C> where C: Deref<Target=str> {
use std::borrow::Cow; use std::borrow::Cow;
impl<'a> NginxServer<'a, String> { 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<str> = Cow::from(String::from("/etc/nginx/sites-enabled/") + domain); let file_path: Cow<str> = Cow::from(String::from("/etc/nginx/sites-enabled/") + domain);
let redir_content = redir_domains.iter().map(|redir_domain| format!("server {{ let redir_content = redir_domains.iter().map(|redir_domain| format!("server {{
@ -60,16 +60,9 @@ impl<'a> NginxServer<'a, String> {
}} }}
", redir_domain, domain)).fold(String::new(), |s, v| s + &v); ", redir_domain, domain)).fold(String::new(), |s, v| s + &v);
let content = String::from(redir_content) + &format!("server {{
listen 80;
# listen 443 ssl;
# ssl_certificate /etc/ssl/.crt;
# ssl_certificate_key /etc/ssl/.key;
server_name {};
root {};
location / {{
let proxy_content = if let Some(socket) = socket_path {
format!("location / {{
try_files $uri @proxy; try_files $uri @proxy;
}} }}
@ -77,8 +70,19 @@ impl<'a> NginxServer<'a, String> {
include fastcgi_params; include fastcgi_params;
proxy_pass http://unix:{}:; proxy_pass http://unix:{}:;
proxy_redirect off; proxy_redirect off;
}}
}}", domain, static_path, socket_path);
}}", socket)
} else { "".to_string() };
let content = String::from(redir_content) + &format!("server {{
listen 80;
# listen 443 ssl;
# ssl_certificate /etc/ssl/.crt;
# ssl_certificate_key /etc/ssl/.key;
server_name {};
root {};
{}
}}", domain, static_path, proxy_content);
NginxServer { NginxServer {
command_runner: command_runner, command_runner: command_runner,
file: FileSymbol::new(file_path, content) file: FileSymbol::new(file_path, content)

Loading…
Cancel
Save