Make proxy in nginx server optional
This commit is contained in:
parent
90cd386dff
commit
d5a3a85e9a
1 changed files with 17 additions and 13 deletions
|
|
@ -49,7 +49,7 @@ pub struct NginxServer<'a, C> where C: Deref<Target=str> {
|
|||
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<str> = 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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue