Browse Source

Refactor nginx

master
Adrian Heine 5 years ago
parent
commit
c954272947
  1. 75
      src/symbols/factory.rs
  2. 6
      src/symbols/nginx/server.rs

75
src/symbols/factory.rs

@ -119,6 +119,7 @@ env[PATH] = /usr/local/bin:/usr/bin:/bin
&'a self,
host_name: &'static str,
root_dir: Cow<'a, str>,
additional_config: &'a str,
) -> Box<dyn Action + 'a> {
let user_name = self.policy.user_name_for_host(host_name);
let socket = self.get_php_fpm_pool_socket_path(&user_name);
@ -126,7 +127,13 @@ env[PATH] = /usr/local/bin:/usr/bin:/bin
self.get_php_fpm_pool(&user_name),
self.get_nginx_acme_server(
host_name,
NginxServer::new_php(host_name, socket.into(), root_dir, self.command_runner),
NginxServer::new_php(
host_name,
socket.into(),
root_dir,
self.command_runner,
additional_config,
),
),
]))
}
@ -136,29 +143,15 @@ env[PATH] = /usr/local/bin:/usr/bin:/bin
host_name: &'static str,
root_dir: Cow<'a, str>,
) -> Box<dyn Action + 'a> {
let user_name = self.policy.user_name_for_host(host_name);
let socket = self.get_php_fpm_pool_socket_path(&user_name);
Box::new(ListAction::new(vec![
self.get_php_fpm_pool(&user_name),
self.get_nginx_acme_server(
host_name,
NginxServer::new(
host_name,
server_config(
self.serve_php(
host_name,
&format!(
"{}
root_dir,
"
location / {{
try_files $uri $uri/ /index.php?$args;
}}
",
php_server_config_snippet(socket.into(), root_dir)
),
),
self.command_runner,
),
),
]))
)
}
pub fn serve_dokuwiki<'a>(
@ -205,18 +198,10 @@ env[PATH] = /usr/local/bin:/usr/bin:/bin
host_name: &'static str,
root_dir: Cow<'a, str>,
) -> Box<dyn Action + 'a> {
let user_name = self.policy.user_name_for_host(host_name);
let socket = self.get_php_fpm_pool_socket_path(&user_name);
Box::new(ListAction::new(vec![
self.get_php_fpm_pool(&user_name),
self.get_nginx_acme_server(
host_name,
NginxServer::new(
self.serve_php(
host_name,
server_config(
host_name,
&format!(
"{}
root_dir,
"
client_max_body_size 500M;
# Disable gzip to avoid the removal of the ETag header
@ -229,17 +214,17 @@ env[PATH] = /usr/local/bin:/usr/bin:/bin
error_page 403 /core/templates/403.php;
error_page 404 /core/templates/404.php;
location = /robots.txt {{
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}}
}
location ~ ^/(?:\\.htaccess|data|config|db_structure\\.xml|README) {{
location ~ ^/(?:\\.htaccess|data|config|db_structure\\.xml|README) {
deny all;
}}
}
location / {{
location / {
# The following 2 rules are only needed with webfinger
rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last;
@ -250,28 +235,22 @@ env[PATH] = /usr/local/bin:/usr/bin:/bin
rewrite ^(/core/doc/[^\\/]+/)$ $1/index.html;
try_files $uri $uri/ /index.php;
}}
}
# Adding the cache control header for js and css files
# Make sure it is BELOW the location ~ \\.php(?:$|/) {{ block
location ~* \\.(?:css|js)$ {{
# Make sure it is BELOW the location ~ \\.php(?:$|/) { block
location ~* \\.(?:css|js)$ {
add_header Cache-Control \"public, max-age=7200\";
# Optional: Don't log access to assets
access_log off;
}}
}
# Optional: Don't log access to other assets
location ~* \\.(?:jpg|jpeg|gif|bmp|ico|png|swf)$ {{
location ~* \\.(?:jpg|jpeg|gif|bmp|ico|png|swf)$ {
access_log off;
}}
}
",
php_server_config_snippet(socket.into(), root_dir)
),
),
self.command_runner,
),
),
]))
)
}
pub fn serve_redir<'a>(

6
src/symbols/nginx/server.rs

@ -171,8 +171,12 @@ location @proxy {{
socket_path: Cow<'a, str>,
static_path: Cow<'a, str>,
command_runner: &'a C,
additional_config: &'a str,
) -> Self {
let content = server_config(domain, &php_server_config_snippet(socket_path, static_path));
let content = server_config(
domain,
&(php_server_config_snippet(socket_path, static_path) + additional_config),
);
NginxServer::new(domain, content, command_runner)
}

Loading…
Cancel
Save