scripts/nginx_config_maker/model.wordpress.mjs

98 lines
3.1 KiB
JavaScript
Raw Normal View History

2023-06-12 23:13:15 +02:00
/**
* turns a domain config to two config files for nginx web sever on proxmox and its container
* @param domainConfig
* @returns {{homeNginxConf: string, containerNginxConf: string}}
*/
2023-06-12 23:27:17 +02:00
export function makeHostFileForWordpress (domainConfig) {
2023-06-12 23:13:15 +02:00
/**
* example:
* # redirect to https+www without www from https
* server {
listen 443 http2;
listen [::]:443 http2;
server_name ${domainConfig.name};
return 301 https://${domainConfig.name}$request_uri;
}
* @type {{homeNginxConf: string, containerNginxConf: string}}
*/
const model = {
2023-06-27 13:22:03 +02:00
noContainerNginxConf: ``,
2023-06-12 23:13:15 +02:00
homeNginxConf: `
# ============ ${domainConfig.name} ===============
2023-06-12 23:41:37 +02:00
# ---------- un site utilisant Wordpress ----------
2023-06-12 23:13:15 +02:00
server {
# redirect to https from http
2023-06-12 23:33:07 +02:00
server_name ${domainConfig.domain};
2023-06-12 23:13:15 +02:00
listen 80 http2;
2023-06-12 23:33:07 +02:00
return 301 https://${domainConfig.domain}$request_uri;
2023-06-12 23:13:15 +02:00
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
2023-06-12 23:33:07 +02:00
server_name ${domainConfig.domain};
ssl_certificate /etc/letsencrypt/live/${domainConfig.domain}-0001/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/${domainConfig.domain}-0001/privkey.pem;
2023-06-12 23:13:15 +02:00
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload";
location / {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
# Container tksites
proxy_pass ${domainConfig.LXCcontainerProtocol}://${domainConfig.LXCcontainerLocalIP};
}
add_header Permissions-Policy "interest-cohort=()";
}
`,
2023-06-12 23:27:17 +02:00
containerNginxConf: `
# ============ ${domainConfig.name} | côté conteneur LXC ===============
server {
2023-06-12 23:33:07 +02:00
if ($host = ${domainConfig.domain}) {
2023-06-12 23:27:17 +02:00
return 301 https://$host$request_uri;
2023-06-12 23:33:07 +02:00
}
2023-06-12 23:27:17 +02:00
listen 80 ;
listen [::]:80 ;
2023-06-12 23:33:07 +02:00
server_name ${domainConfig.domain};
2023-06-12 23:41:37 +02:00
2023-06-12 23:33:07 +02:00
# Path to the root of your installation
root /home/www/tykayn/${domainConfig.domain}/;
2023-06-12 23:27:17 +02:00
index index.php;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location / {
# This is cool because no php is touched for static content.
# include the "?$args" part so non-default permalinks doesn't break when using query string
try_files $uri $uri/ /index.php?$args;
}
location ~ \\.php$ {
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_pass php-handler;
}
location ~* \\.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
2023-06-12 23:33:07 +02:00
add_header Permissions-Policy "interest-cohort=()";
2023-06-12 23:27:17 +02:00
}
2023-06-12 23:33:07 +02:00
# ========================== ${domainConfig.name} | fin ================ #
2023-06-12 23:27:17 +02:00
`
2023-06-12 23:13:15 +02:00
}
return model
}