Compare commits

..

1 Commits

Author SHA1 Message Date
Hadrien a30b73b83d nginx 2022-06-22 20:11:36 +02:00
19 changed files with 3154 additions and 50 deletions

5
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,5 @@
{
"yaml.schemas": {
"https://raw.githubusercontent.com/ansible-community/schemas/main/f/ansible.json#/$defs/playbook": "file:///home/hadrien/git/ansible-fuz/matrix.yml"
}
}

View File

@ -7,14 +7,11 @@
# roles:
# - geerlingguy.pip
tasks:
- name: Faire une full upgrade
apt:
- apt:
upgrade: yes
- name: Programmes utiles installés
apt:
- apt:
name:
- python3-pip
- certbot
- tmux
- bash-completion
- rsync

81
files/nginx/nginx.conf Executable file
View File

@ -0,0 +1,81 @@
# https://www.digitalocean.com/community/tools/nginx
user www-data;
pid /run/nginx.pid;
worker_processes auto;
worker_rlimit_nofile 65535;
# Load modules
include /etc/nginx/modules-enabled/*.conf;
events {
multi_accept on;
worker_connections 65535;
}
http {
charset utf-8;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
server_tokens off;
log_not_found off;
types_hash_max_size 2048;
types_hash_bucket_size 64;
client_max_body_size 16M;
# MIME
include mime.types;
default_type application/octet-stream;
# Logging
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log warn;
# SSL
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off;
# Diffie-Hellman parameter for DHE ciphersuites
ssl_dhparam /etc/nginx/dhparam.pem;
# Mozilla Intermediate configuration
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
# OCSP Stapling
ssl_stapling on;
ssl_stapling_verify on;
# Connection header for WebSocket reverse proxy
map $http_upgrade $connection_upgrade {
default upgrade;
"" close;
}
map $remote_addr $proxy_forwarded_elem {
# IPv4 addresses can be sent as-is
~^[0-9.]+$ "for=$remote_addr";
# IPv6 addresses need to be bracketed and quoted
~^[0-9A-Fa-f:.]+$ "for=\"[$remote_addr]\"";
# Unix domain socket names cannot be represented in RFC 7239 syntax
default "for=unknown";
}
map $http_forwarded $proxy_add_forwarded {
# If the incoming Forwarded header is syntactically valid, append to it
"~^(,[ \\t]*)*([!#$%&'*+.^_`|~0-9A-Za-z-]+=([!#$%&'*+.^_`|~0-9A-Za-z-]+|\"([\\t \\x21\\x23-\\x5B\\x5D-\\x7E\\x80-\\xFF]|\\\\[\\t \\x21-\\x7E\\x80-\\xFF])*\"))?(;([!#$%&'*+.^_`|~0-9A-Za-z-]+=([!#$%&'*+.^_`|~0-9A-Za-z-]+|\"([\\t \\x21\\x23-\\x5B\\x5D-\\x7E\\x80-\\xFF]|\\\\[\\t \\x21-\\x7E\\x80-\\xFF])*\"))?)*([ \\t]*,([ \\t]*([!#$%&'*+.^_`|~0-9A-Za-z-]+=([!#$%&'*+.^_`|~0-9A-Za-z-]+|\"([\\t \\x21\\x23-\\x5B\\x5D-\\x7E\\x80-\\xFF]|\\\\[\\t \\x21-\\x7E\\x80-\\xFF])*\"))?(;([!#$%&'*+.^_`|~0-9A-Za-z-]+=([!#$%&'*+.^_`|~0-9A-Za-z-]+|\"([\\t \\x21\\x23-\\x5B\\x5D-\\x7E\\x80-\\xFF]|\\\\[\\t \\x21-\\x7E\\x80-\\xFF])*\"))?)*)?)*$" "$http_forwarded, $proxy_forwarded_elem";
# Otherwise, replace it
default "$proxy_forwarded_elem";
}
# Load configs
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}

View File

@ -0,0 +1,52 @@
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name fuz.re;
root /var/www/fuz.re/public;
# SSL
ssl_certificate /etc/letsencrypt/live/fuz.re/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/fuz.re/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/fuz.re/chain.pem;
# security
include snippets/security.conf;
# index.html fallback
location / {
try_files $uri $uri/ /index.html;
}
# index.php fallback
location ~ ^/api/ {
try_files $uri $uri/ /index.php?$query_string;
}
# additional config
include snippets/general.conf;
}
# subdomains redirect
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name fuz.re www.fuz.re;
# SSL
ssl_certificate /etc/letsencrypt/live/fuz.re/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/fuz.re/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/fuz.re/chain.pem;
return 301 https://fuz.re$request_uri;
}
# HTTP redirect
server {
listen 80;
listen [::]:80;
server_name fuz.re www.fuz.re;
include snippets/letsencrypt.conf;
location / {
return 301 https://fuz.re$request_uri;
}
}

View File

@ -0,0 +1,38 @@
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name matrix.fuz.re;
# SSL
ssl_certificate /etc/letsencrypt/live/matrix.fuz.re/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/matrix.fuz.re/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/matrix.fuz.re/chain.pem;
# security
include snippets/security.conf;
# logging
access_log /var/log/nginx/matrix.fuz.re.access.log;
error_log /var/log/nginx/matrix.fuz.re.error.log warn;
# reverse proxy
location / {
proxy_pass http://127.0.0.1:8080;
include snippets/proxy.conf;
}
# additional config
include snippets/general.conf;
}
# HTTP redirect
server {
listen 80;
listen [::]:80;
server_name matrix.fuz.re;
include snippets/letsencrypt.conf;
location / {
return 301 https://matrix.fuz.re$request_uri;
}
}

View File

@ -0,0 +1,18 @@
# favicon.ico
location = /favicon.ico {
log_not_found off;
access_log off;
}
# robots.txt
location = /robots.txt {
log_not_found off;
access_log off;
}
# gzip
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml;

View File

@ -0,0 +1,4 @@
# ACME-challenge
location ^~ /.well-known/acme-challenge/ {
root /var/www/_letsencrypt;
}

18
files/nginx/snippets/proxy.conf Executable file
View File

@ -0,0 +1,18 @@
proxy_http_version 1.1;
proxy_cache_bypass $http_upgrade;
# Proxy headers
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Forwarded $proxy_add_forwarded;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
# Proxy timeouts
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;

View File

@ -0,0 +1,12 @@
# security headers
add_header X-XSS-Protection "1; mode=block" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "no-referrer-when-downgrade" always;
add_header Content-Security-Policy "default-src 'self' http: https: ws: wss: data: blob: 'unsafe-inline'; frame-ancestors 'self';" always;
add_header Permissions-Policy "interest-cohort=()" always;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
# . files
location ~ /\.(?!well-known) {
deny all;
}

View File

@ -1,2 +1,2 @@
# sonic ansible_host=sonic.fuz.re
sonic ansible_host=sonic.fuz.re
octo.fuz.re

View File

@ -1,24 +0,0 @@
- hosts: octo.fuz.re
become: yes
tasks:
- name: Lighttpd installé
apt:
name: lighttpd
- name: Copie la conf
copy:
src: files/lighttpd.conf
dest: /etc/lighttpd/lighttpd.conf
notify: Restart de lighttpd
- name: On charge lighttpd
service:
name: lighttpd
state: started
enabled: yes
handlers:
- name: Restart de lighttpd
service:
name: lighttpd
state: restarted

View File

@ -2,7 +2,7 @@
- import_playbook: adminsys-classique.yml
# Octo
- import_playbook: matrix.yml
- import_playbook: lighttpd.yml
# - import_playbook: nginx.yml
# - import_playbook: certbot.yml
# Sonic

View File

@ -1,30 +1,21 @@
- hosts: octo.fuz.re
become: yes
tasks:
- name: synapse installé et upgradé
become: yes
apt:
name: matrix-synapse
update_cache: yes
upgrade: yes
- name: Config Synapse conforme à ce qu'il y a dans ce dépôt Ansible
template:
src: templates/homeserver.yaml.j2
dest: /etc/matrix-synapse/homeserver.yaml
- name: On copie la conf du matrix
template:
src: templates/nginx/matrix.yaml.j2
dest: /etc/nginx/sites_enabled/matrix
# - name: Config Synapse conforme à ce qu'il y a dans ce dépôt Ansible
# template:
# src: templates/homeserver.yaml.j2
# dest: /etc/matrix-synapse/homeserver.yaml
- name: Postgres lancé
service:
name: postgresql@13-main
state: started
enabled: yes
- name: Synapse lancé
service:
name: matrix-synapse
state: started
enabled: yes
vars:
- matrix_server_name: matrix.fuz.re
- synapse_postgres_password: !vault |

12
nginx.yml Normal file
View File

@ -0,0 +1,12 @@
- hosts: octo.fuz.re
become: yes
tasks:
- name: Nginx installé
apt:
name: nginx
- name: On charge Nginx
service:
name: nginx
state: started
enabled: yes

20
requirements.yml Normal file
View File

@ -0,0 +1,20 @@
# from galaxy
# - src: geerlingguy.pip
# - src: geerlingguy.postgresql
# - src: https://github.com/geerlingguy/ansible-role-certbot
# scm: git
# from GitHub, overriding the name and specifying a specific tag
# - src: https://github.com/bennojoy/nginx
# version: master
# name: nginx_role
# from a webserver, where the role is packaged in a tar.gz
# - src: https://some.webserver.example.com/files/master.tar.gz
# name: http-role
# from GitLab or other git-based scm, using git+ssh
# - src: https://gitlab.com/famedly/ansible/synapse
# scm: git
# version: "0.1" # quoted, so YAML doesn't parse this as a floating-point value

1
sonic/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
homeserver.yaml

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,24 @@
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
# For the federation port
listen 8448 ssl http2 default_server;
listen [::]:8448 ssl http2 default_server;
server_name matrix.fuz.re;
location ~ ^(/_matrix|/_synapse/client) {
# note: do not add a path (even a single /) after the port in `proxy_pass`,
# otherwise nginx will canonicalise the URI and cause signature verification
# errors.
proxy_pass http://localhost:8008;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $host;
# Nginx by default only allows file uploads up to 1M in size
# Increase client_max_body_size to match max_upload_size defined in homeserver.yaml
client_max_body_size 50M;
}
}