Add uwsgi
This commit is contained in:
parent
e23b41c37c
commit
7d973372cc
2 changed files with 88 additions and 4 deletions
|
|
@ -11,3 +11,55 @@ pub fn acme_challenges_snippet<P: AsRef<Path>>(path: P) -> String {
|
||||||
path.as_ref().to_str().unwrap()
|
path.as_ref().to_str().unwrap()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use super::{server_config, uwsgi_snippet};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_uwsgi() {
|
||||||
|
assert_eq!(
|
||||||
|
server_config(
|
||||||
|
"testdomain",
|
||||||
|
"/certpath",
|
||||||
|
"/keypath",
|
||||||
|
uwsgi_snippet("/uwsgi.sock", "/static"),
|
||||||
|
"/challenges_snippet.conf"
|
||||||
|
),
|
||||||
|
"server {
|
||||||
|
listen 443 ssl http2;
|
||||||
|
listen [::]:443 ssl http2;
|
||||||
|
server_name testdomain;
|
||||||
|
include \"/challenges_snippet.conf\";
|
||||||
|
|
||||||
|
ssl_certificate /certpath;
|
||||||
|
ssl_certificate_key /keypath;
|
||||||
|
add_header Strict-Transport-Security \"max-age=31536000\";
|
||||||
|
|
||||||
|
root /static;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
try_files $uri @proxy;
|
||||||
|
}
|
||||||
|
|
||||||
|
location @proxy {
|
||||||
|
include uwsgi_params;
|
||||||
|
uwsgi_pass unix:/uwsgi.sock;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Redirect all HTTP links to the matching HTTPS page
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
listen [::]:80;
|
||||||
|
server_name testdomain;
|
||||||
|
include \"/challenges_snippet.conf\";
|
||||||
|
|
||||||
|
location / {
|
||||||
|
return 301 https://$host$request_uri;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -85,14 +85,20 @@ pub fn redir_snippet(target: &str) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait SocketSpec {
|
pub trait SocketSpec {
|
||||||
fn to_nginx(&self) -> String;
|
fn to_proxy_pass(&self) -> String;
|
||||||
|
fn to_uwsgi_pass(&self) -> String;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: AsRef<Path>> SocketSpec for T {
|
impl<T: AsRef<Path>> SocketSpec for T {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
fn to_nginx(&self) -> String {
|
fn to_proxy_pass(&self) -> String {
|
||||||
format!("unix:{}:", self.as_ref().to_str().unwrap())
|
format!("unix:{}:", self.as_ref().to_str().unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
fn to_uwsgi_pass(&self) -> String {
|
||||||
|
format!("unix:{}", self.as_ref().to_str().unwrap())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
@ -107,7 +113,12 @@ impl LocalTcpSocket {
|
||||||
|
|
||||||
impl SocketSpec for LocalTcpSocket {
|
impl SocketSpec for LocalTcpSocket {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
fn to_nginx(&self) -> String {
|
fn to_proxy_pass(&self) -> String {
|
||||||
|
format!("localhost:{}", self.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
fn to_uwsgi_pass(&self) -> String {
|
||||||
format!("localhost:{}", self.0)
|
format!("localhost:{}", self.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -129,7 +140,28 @@ pub fn proxy_snippet<S: SocketSpec, STATIC: AsRef<Path>>(
|
||||||
proxy_redirect off;
|
proxy_redirect off;
|
||||||
}}",
|
}}",
|
||||||
static_path.as_ref().to_str().unwrap(),
|
static_path.as_ref().to_str().unwrap(),
|
||||||
socket_path.to_nginx()
|
socket_path.to_proxy_pass()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub fn uwsgi_snippet<S: SocketSpec, STATIC: AsRef<Path>>(
|
||||||
|
socket_path: S,
|
||||||
|
static_path: STATIC,
|
||||||
|
) -> String {
|
||||||
|
format!(
|
||||||
|
"root {};
|
||||||
|
|
||||||
|
location / {{
|
||||||
|
try_files $uri @proxy;
|
||||||
|
}}
|
||||||
|
|
||||||
|
location @proxy {{
|
||||||
|
include uwsgi_params;
|
||||||
|
uwsgi_pass {};
|
||||||
|
}}",
|
||||||
|
static_path.as_ref().to_str().unwrap(),
|
||||||
|
socket_path.to_uwsgi_pass()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue