build from inception
This commit is contained in:
87
srcs/requirements/nginx/Dockerfile
Normal file
87
srcs/requirements/nginx/Dockerfile
Normal file
@@ -0,0 +1,87 @@
|
||||
# debian (~ 180s) --------------------------------------------
|
||||
|
||||
# FROM debian:buster
|
||||
#
|
||||
# # vim for debug
|
||||
# RUN apt update && apt install -y \
|
||||
# nginx openssl \
|
||||
# vim \
|
||||
# && \
|
||||
# rm -rf /var/lib/apt/lists/*
|
||||
#
|
||||
# # nginx conf
|
||||
# COPY ./conf/nginx.conf.debian /etc/nginx/nginx.conf
|
||||
# COPY ./conf/inception_nginx.conf /etc/nginx/conf.d/
|
||||
|
||||
# alpine (~ 45s) ---------------------------------------------
|
||||
|
||||
FROM alpine:3.15
|
||||
|
||||
# vim and bash for debug
|
||||
RUN apk update && apk add \
|
||||
nginx openssl \
|
||||
vim bash \
|
||||
&& \
|
||||
rm -rf /var/cache/apk*
|
||||
|
||||
# nginx conf
|
||||
COPY ./conf/nginx.conf.alpine /etc/nginx/nginx.conf
|
||||
COPY ./conf/inception_nginx.conf /etc/nginx/http.d/
|
||||
|
||||
# create user www-data and assign it to group www-data
|
||||
RUN adduser -S www-data && \
|
||||
adduser www-data www-data
|
||||
|
||||
RUN mkdir -p /var/www/html
|
||||
|
||||
# common -----------------------------------------------------
|
||||
|
||||
# replace WP_URL
|
||||
ARG WP_URL
|
||||
RUN sed -i "s/\${WP_URL}/${WP_URL}/g" /etc/nginx/http.d/inception_nginx.conf
|
||||
|
||||
# personalized index.html
|
||||
COPY ./conf/index.html /data/www/
|
||||
|
||||
# create ssl certificate
|
||||
RUN mkdir -p /etc/ssl/private /etc/ssl/certs
|
||||
RUN openssl req -newkey rsa:2048 -nodes -x509 -days 365 \
|
||||
-subj "/C=fr/ST=ile-de-france/L=paris/O=42/OU=inception/CN=${WP_URL}" \
|
||||
-keyout /etc/ssl/private/${WP_URL}.key \
|
||||
-out /etc/ssl/certs/${WP_URL}.crt
|
||||
|
||||
ENTRYPOINT [ "nginx", "-g", "daemon off;" ]
|
||||
|
||||
|
||||
#
|
||||
# -g 'daemon off' :
|
||||
# daemon off, to avoid the main process of nginx to quit after creating its childs, and therefore make docker exit
|
||||
# https://stackoverflow.com/questions/18861300/how-to-run-nginx-within-a-docker-container-without-halting
|
||||
#
|
||||
# ssl certificate :
|
||||
# openssl faq : https://www.openssl.org/docs/faq.html
|
||||
# openssl req : create ertificate request, and optionally create self signed certificates
|
||||
# openssl req man : https://www.openssl.org/docs/man1.0.2/man1/openssl-req.html
|
||||
# exemple of openssl with nginx on docker : https://www.johnmackenzie.co.uk/posts/using-self-signed-ssl-certificates-with-docker-and-nginx/
|
||||
#
|
||||
# usually the steps are :
|
||||
# - create a server private key : `openssl genrsa -out server.key 2048`
|
||||
# - create a CSR (certificate signing request) with the key : `openssl req -new -key server.key -out www.exemple.com.csr`
|
||||
# - it will ask for :
|
||||
# - Country Name (2 letter code)
|
||||
# - State or Province Name (full name)
|
||||
# - Locality Name (eg, city)
|
||||
# - Organization Name (eg, company)
|
||||
# - Organizational Unit Name (eg, section)
|
||||
# - Common Name (eg, fully qualified host name)
|
||||
# - Email Address (put nothing)
|
||||
# - now ask to a CA (certificate authority) for a certificate.crt by giving them your request.csr
|
||||
#
|
||||
# alternatively we can generate our self-signed certificate with the `openssl req` command :
|
||||
# - `x509` option is used to output a certificate instead of a certificate request
|
||||
# - a request is created from scratch, if it is not given with `-in`
|
||||
# - `newkey` generate a new private key, unless `-key` is given
|
||||
# - `nodes` create a private key without encryption (no passphrase needed)
|
||||
#
|
||||
# SO discussion about becomming a real CA to have a certificate that works in deployement : https://stackoverflow.com/questions/10175812/how-to-generate-a-self-signed-ssl-certificate-using-openssl
|
||||
#
|
||||
91
srcs/requirements/nginx/conf/default
Normal file
91
srcs/requirements/nginx/conf/default
Normal file
@@ -0,0 +1,91 @@
|
||||
##
|
||||
# You should look at the following URL's in order to grasp a solid understanding
|
||||
# of Nginx configuration files in order to fully unleash the power of Nginx.
|
||||
# https://www.nginx.com/resources/wiki/start/
|
||||
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
|
||||
# https://wiki.debian.org/Nginx/DirectoryStructure
|
||||
#
|
||||
# In most cases, administrators will remove this file from sites-enabled/ and
|
||||
# leave it as reference inside of sites-available where it will continue to be
|
||||
# updated by the nginx packaging team.
|
||||
#
|
||||
# This file will automatically load configuration files provided by other
|
||||
# applications, such as Drupal or Wordpress. These applications will be made
|
||||
# available underneath a path with that package name, such as /drupal8.
|
||||
#
|
||||
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
|
||||
##
|
||||
|
||||
# Default server configuration
|
||||
#
|
||||
server {
|
||||
listen 80 default_server;
|
||||
listen [::]:80 default_server;
|
||||
|
||||
# SSL configuration
|
||||
#
|
||||
# listen 443 ssl default_server;
|
||||
# listen [::]:443 ssl default_server;
|
||||
#
|
||||
# Note: You should disable gzip for SSL traffic.
|
||||
# See: https://bugs.debian.org/773332
|
||||
#
|
||||
# Read up on ssl_ciphers to ensure a secure configuration.
|
||||
# See: https://bugs.debian.org/765782
|
||||
#
|
||||
# Self signed certs generated by the ssl-cert package
|
||||
# Don't use them in a production server!
|
||||
#
|
||||
# include snippets/snakeoil.conf;
|
||||
|
||||
root /var/www/html;
|
||||
|
||||
# Add index.php to the list if you are using PHP
|
||||
index index.html index.htm index.nginx-debian.html;
|
||||
|
||||
server_name _;
|
||||
|
||||
location / {
|
||||
# First attempt to serve request as file, then
|
||||
# as directory, then fall back to displaying a 404.
|
||||
try_files $uri $uri/ =404;
|
||||
}
|
||||
|
||||
# pass PHP scripts to FastCGI server
|
||||
#
|
||||
#location ~ \.php$ {
|
||||
# include snippets/fastcgi-php.conf;
|
||||
#
|
||||
# # With php-fpm (or other unix sockets):
|
||||
# fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
|
||||
# # With php-cgi (or other tcp sockets):
|
||||
# fastcgi_pass 127.0.0.1:9000;
|
||||
#}
|
||||
|
||||
# deny access to .htaccess files, if Apache's document root
|
||||
# concurs with nginx's one
|
||||
#
|
||||
#location ~ /\.ht {
|
||||
# deny all;
|
||||
#}
|
||||
}
|
||||
|
||||
|
||||
# Virtual Host configuration for example.com
|
||||
#
|
||||
# You can move that to a different file under sites-available/ and symlink that
|
||||
# to sites-enabled/ to enable it.
|
||||
#
|
||||
#server {
|
||||
# listen 80;
|
||||
# listen [::]:80;
|
||||
#
|
||||
# server_name example.com;
|
||||
#
|
||||
# root /var/www/example.com;
|
||||
# index index.html;
|
||||
#
|
||||
# location / {
|
||||
# try_files $uri $uri/ =404;
|
||||
# }
|
||||
#}
|
||||
34
srcs/requirements/nginx/conf/inception_nginx.conf
Normal file
34
srcs/requirements/nginx/conf/inception_nginx.conf
Normal file
@@ -0,0 +1,34 @@
|
||||
# doc : https://nginx.org/en/docs/dirindex.html
|
||||
|
||||
# WIP redirect http to https
|
||||
#server {
|
||||
# listen 80;
|
||||
# listen [::]:80;
|
||||
# server_name _;
|
||||
# return 301 https://$host$request_uri;
|
||||
#}
|
||||
|
||||
server {
|
||||
listen 443 ssl; # for ipv4, on port 443, specifying that accepted connections should works in ssl mode
|
||||
listen [::]:443 ssl; # for ipv6
|
||||
server_name ${WP_URL};
|
||||
ssl_certificate /etc/ssl/certs/${WP_URL}.crt; # specifies the file with the ssl certificate (self signed here) generated by openssl
|
||||
ssl_certificate_key /etc/ssl/private/${WP_URL}.key; # specifies the file with the secret key of the certificate
|
||||
|
||||
root /var/www/html/; # contains default nginx index.nginx-debian.html
|
||||
index index.html index.php; # defines files that will be used as index (https://nginx.org/en/docs/http/ngx_http_index_module.html)
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ =404; # from /etc/nginx/sites-enabled/default : First attempt to serve request as file, then as directory, then fall back to displaying a 404
|
||||
}
|
||||
|
||||
# pass PHP scripts to FastCGI (PHP-FPM) server
|
||||
location ~ \.php$ {
|
||||
include fastcgi_params;
|
||||
fastcgi_pass wordpress:9000;
|
||||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
||||
|
||||
try_files $uri =404;
|
||||
}
|
||||
}
|
||||
1
srcs/requirements/nginx/conf/index.html
Normal file
1
srcs/requirements/nginx/conf/index.html
Normal file
@@ -0,0 +1 @@
|
||||
hello world !
|
||||
118
srcs/requirements/nginx/conf/nginx.conf.alpine
Normal file
118
srcs/requirements/nginx/conf/nginx.conf.alpine
Normal file
@@ -0,0 +1,118 @@
|
||||
# inception modifications :
|
||||
#
|
||||
# user :
|
||||
# < user www-data
|
||||
# > user nginx
|
||||
#
|
||||
# protocols :
|
||||
#
|
||||
# < ssl_protocols TLSv1.2 TLSv1.3;
|
||||
# > ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
|
||||
#
|
||||
# http :
|
||||
# < client_max_body_size 640m;
|
||||
# > client_max_body_size 1m;
|
||||
|
||||
# /etc/nginx/nginx.conf
|
||||
|
||||
user www-data;
|
||||
|
||||
# Set number of worker processes automatically based on number of CPU cores.
|
||||
worker_processes auto;
|
||||
|
||||
# Enables the use of JIT for regular expressions to speed-up their processing.
|
||||
pcre_jit on;
|
||||
|
||||
# Configures default error logger.
|
||||
error_log /var/log/nginx/error.log warn;
|
||||
|
||||
# Includes files with directives to load dynamic modules.
|
||||
include /etc/nginx/modules/*.conf;
|
||||
|
||||
# Uncomment to include files with config snippets into the root context.
|
||||
# NOTE: This will be enabled by default in Alpine 3.15.
|
||||
#include /etc/nginx/conf.d/*.conf;
|
||||
|
||||
events {
|
||||
# The maximum number of simultaneous connections that can be opened by
|
||||
# a worker process.
|
||||
worker_connections 1024;
|
||||
}
|
||||
http {
|
||||
# Includes mapping of file name extensions to MIME types of responses
|
||||
# and defines the default type.
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
# Name servers used to resolve names of upstream servers into addresses.
|
||||
# It's also needed when using tcpsocket and udpsocket in Lua modules.
|
||||
#resolver 1.1.1.1 1.0.0.1 2606:4700:4700::1111 2606:4700:4700::1001;
|
||||
|
||||
# Don't tell nginx version to the clients. Default is 'on'.
|
||||
server_tokens off;
|
||||
|
||||
# Specifies the maximum accepted body size of a client request, as
|
||||
# indicated by the request header Content-Length. If the stated content
|
||||
# length is greater than this size, then the client receives the HTTP
|
||||
# error code 413. Set to 0 to disable. Default is '1m'.
|
||||
client_max_body_size 640m;
|
||||
|
||||
# Sendfile copies data between one FD and other from within the kernel,
|
||||
# which is more efficient than read() + write(). Default is off.
|
||||
sendfile on;
|
||||
|
||||
# Causes nginx to attempt to send its HTTP response head in one packet,
|
||||
# instead of using partial frames. Default is 'off'.
|
||||
tcp_nopush on;
|
||||
|
||||
|
||||
# Enables the specified protocols. Default is TLSv1 TLSv1.1 TLSv1.2.
|
||||
# TIP: If you're not obligated to support ancient clients, remove TLSv1.1.
|
||||
ssl_protocols TLSv1.2 TLSv1.3;
|
||||
|
||||
# Path of the file with Diffie-Hellman parameters for EDH ciphers.
|
||||
# TIP: Generate with: `openssl dhparam -out /etc/ssl/nginx/dh2048.pem 2048`
|
||||
#ssl_dhparam /etc/ssl/nginx/dh2048.pem;
|
||||
|
||||
# Specifies that our cipher suits should be preferred over client ciphers.
|
||||
# Default is 'off'.
|
||||
ssl_prefer_server_ciphers on;
|
||||
|
||||
# Enables a shared SSL cache with size that can hold around 8000 sessions.
|
||||
# Default is 'none'.
|
||||
ssl_session_cache shared:SSL:2m;
|
||||
|
||||
# Specifies a time during which a client may reuse the session parameters.
|
||||
# Default is '5m'.
|
||||
ssl_session_timeout 1h;
|
||||
|
||||
# Disable TLS session tickets (they are insecure). Default is 'on'.
|
||||
ssl_session_tickets off;
|
||||
|
||||
|
||||
# Enable gzipping of responses.
|
||||
#gzip on;
|
||||
|
||||
# Set the Vary HTTP header as defined in the RFC 2616. Default is 'off'.
|
||||
gzip_vary on;
|
||||
|
||||
# Helper variable for proxying websockets.
|
||||
map $http_upgrade $connection_upgrade {
|
||||
default upgrade;
|
||||
'' close;
|
||||
}
|
||||
|
||||
# Specifies the main log format.
|
||||
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||
'$status $body_bytes_sent "$http_referer" '
|
||||
'"$http_user_agent" "$http_x_forwarded_for"';
|
||||
|
||||
# Sets the path, format, and configuration for a buffered log write.
|
||||
access_log /var/log/nginx/access.log main;
|
||||
|
||||
# Includes virtual hosts configs.
|
||||
include /etc/nginx/http.d/*.conf;
|
||||
}
|
||||
|
||||
# TIP: Uncomment if you use stream module.
|
||||
#include /etc/nginx/stream.conf;
|
||||
98
srcs/requirements/nginx/conf/nginx.conf.debian
Normal file
98
srcs/requirements/nginx/conf/nginx.conf.debian
Normal file
@@ -0,0 +1,98 @@
|
||||
# inception modifications :
|
||||
#
|
||||
# ssl_protocols :
|
||||
# < ssl_protocols TLSv1.3; # Dropping SSLv3, ref: POODLE
|
||||
# > ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
|
||||
# gzip :
|
||||
# < gzip off;
|
||||
# > gzip on;
|
||||
# sites-enabled :
|
||||
# < # include /etc/nginx/sites-enabled/*;
|
||||
# > include /etc/nginx/sites-enabled/*;
|
||||
# doc : https://nginx.org/en/docs/dirindex.html
|
||||
|
||||
user www-data; # process owner name, can be anything
|
||||
worker_processes auto; # a worker is a process that handles incoming requests, auto to automatically adjust the number of processes available
|
||||
pid /run/nginx.pid; # defines a file that will store the process id of the main process
|
||||
include /etc/nginx/modules-enabled/*.conf; # include a file
|
||||
|
||||
events { # section for connection processing directives
|
||||
worker_connections 768; # max number of connection that can be opened by a worker process
|
||||
# multi_accept on;
|
||||
}
|
||||
|
||||
http { # section for http server directives
|
||||
##
|
||||
# Basic Settings
|
||||
##
|
||||
|
||||
sendfile on; # enable the use of linux sendfil() function, that transfer data directly betzeen fd, so withour copying to intermediate memory buffer, it increases performances in most cases (https://stackoverflow.com/questions/58066785/always-use-sendfile-with-nginx-on-linux)
|
||||
tcp_nopush on; # enables the socket option TCP_CORK/TCP_NOPUSH, that allows to send packets filled with more datas (https://baus.net/on-tcp_cork/)
|
||||
tcp_nodelay on; # opposit of TCP_CORK, TCP_NODELAY says the application to send datas as soon as it receives it, both options are exclusives but can work together in modern kernel (https://stackoverflow.com/questions/3761276/when-should-i-use-tcp-nodelay-and-when-tcp-cork)
|
||||
keepalive_timeout 65; # in seconds, defines time before closing a connexion without activity
|
||||
types_hash_max_size 2048; # maximum size for the list that stores duplicates of the hash table, size of the hash table is chosen accordingly (https://nginx.org/en/docs/hash.html, hash table : https://www.youtube.com/watch?v=KyUTuwz_b7Q)
|
||||
# server_tokens off;
|
||||
|
||||
# server_names_hash_bucket_size 64;
|
||||
# server_name_in_redirect off;
|
||||
|
||||
include /etc/nginx/mime.types; # include a file
|
||||
default_type application/octet-stream; # defines the default MIME type (default is text/plain)
|
||||
|
||||
##
|
||||
# SSL Settings
|
||||
##
|
||||
|
||||
ssl_protocols TLSv1.3; # Dropping SSLv3, ref: POODLE # enables the specified protocols. The TLSv1.1 and TLSv1.2 parameters works only when OpenSSL 1.0.1 or higher is used, and the TLSv1.3 only when OpenSSL 1.1.1 or higher is used
|
||||
ssl_prefer_server_ciphers on; # Specifies that server ciphers should be preferred over client ciphers when using the SSLv3 and TLS protocols (a cipher is "an algorithm for performing encryption or decryption, a series of [...] steps that can be followed as a procedure" https://en.wikipedia.org/wiki/Cipher_suite)
|
||||
|
||||
##
|
||||
# Logging Settings
|
||||
##
|
||||
|
||||
access_log /var/log/nginx/access.log; # defines where to write the access logs. if gzip is used, the log will be buffered
|
||||
error_log /var/log/nginx/error.log; # defines where to write the error logs. if gzip is used, the log will be buffered
|
||||
|
||||
##
|
||||
# Gzip Settings
|
||||
##
|
||||
|
||||
gzip off; # enable gzipping of responses. gzip is an algorithm that compress the data (disabled for security reasons : https://bugs.debian.org/773332)
|
||||
|
||||
# gzip_vary on;
|
||||
# gzip_proxied any;
|
||||
# gzip_comp_level 6;
|
||||
# gzip_buffers 16 8k;
|
||||
# gzip_http_version 1.1;
|
||||
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
|
||||
|
||||
##
|
||||
# Virtual Host Configs
|
||||
##
|
||||
|
||||
include /etc/nginx/conf.d/*.conf; # include the *.conf files found in conf.d folder. do the same as "sites-enabled" with another approach : you put your .conf files for the site inside this folder, and if you want to disable a config file you just rename it to no have a .conf suffix
|
||||
# include /etc/nginx/sites-enabled/*; # include all the (symlink) files found in sites-enabled folder. do the same as "conf.d" with another approach : you put all your configurations files into a "/etc/nginx/sites-available/" folder, and you put symlinks of a selection of thoses files that you want to use for the site, into "/etc/nginx/sites-enabled/" folder (bad practice : https://serverfault.com/questions/527630/difference-in-sites-available-vs-sites-enabled-vs-conf-d-directories-nginx#answer-870709)
|
||||
}
|
||||
|
||||
|
||||
#mail {
|
||||
# # See sample authentication script at:
|
||||
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
|
||||
#
|
||||
# # auth_http localhost/auth.php;
|
||||
# # pop3_capabilities "TOP" "USER";
|
||||
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
|
||||
#
|
||||
# server {
|
||||
# listen localhost:110;
|
||||
# protocol pop3;
|
||||
# proxy on;
|
||||
# }
|
||||
#
|
||||
# server {
|
||||
# listen localhost:143;
|
||||
# protocol imap;
|
||||
# proxy on;
|
||||
# }
|
||||
#}
|
||||
|
||||
Reference in New Issue
Block a user