Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c616317

Browse files
committed
Modify domain and email
1 parent d628b15 commit c616317

File tree

7 files changed

+362
-0
lines changed

7 files changed

+362
-0
lines changed

‎docker-compose.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
version: '3'
2+
services:
3+
4+
nginx:
5+
image: nginx:1.23-alpine
6+
restart: unless-stopped
7+
ports:
8+
- "80:80"
9+
- "443:443"
10+
volumes:
11+
- ./public:/var/www/public
12+
#- ./nginx.localhost:/etc/nginx/conf.d #uncomment this line if certbot generate for the first time and run ./init-letsencrypt.sh
13+
- ./nginx:/etc/nginx/conf.d #uncomment this line after certbot generated cert & comment line above. Then run docker-compose up/docker-compose up -d
14+
- ./certbot/conf:/etc/letsencrypt
15+
- ./certbot/www:/var/www/certbot
16+
environment:
17+
- TZ=Asia/Jakarta
18+
command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'"
19+
20+
certbot:
21+
image: certbot/certbot
22+
restart: unless-stopped
23+
volumes:
24+
- ./certbot/conf/:/etc/letsencrypt
25+
- ./certbot/logs/:/var/log/letsencrypt
26+
- ./certbot/www:/var/www/certbot
27+
depends_on:
28+
- nginx
29+
environment:
30+
- TZ=Asia/Jakarta
31+
entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"
32+
33+
php:
34+
build:
35+
context: .
36+
dockerfile: php/Dockerfile
37+
volumes:
38+
- .:/var/www
39+
environment:
40+
- TZ=Asia/Jakarta
41+
42+
mysql:
43+
image: mysql:8
44+
ports:
45+
- "3306:3306"
46+
environment:
47+
- MYSQL_ROOT_PASSWORD=0123456789
48+
- MYSQL_USER=dbuser
49+
- MYSQL_PASSWORD=9876543210
50+
- MYSQL_DATABASE=dbname
51+
- TZ=Asia/Jakarta
52+
volumes:
53+
- "mysql_data:/var/lib/mysql"
54+
55+
pgsql:
56+
image: postgres:15-alpine
57+
restart: always
58+
ports:
59+
- "5432:5432"
60+
environment:
61+
- POSTGRES_USER=postgres
62+
- POSTGRES_PASSWORD=example
63+
- TZ=Asia/Jakarta
64+
volumes:
65+
- "pgsql_data:/var/lib/postgresql/data"
66+
67+
volumes:
68+
mysql_data: { driver: local }
69+
pgsql_data: { driver: local }

‎init-letsencrypt.sh

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/bin/bash
2+
3+
if ! [ -x "$(command -v docker-compose)" ]; then
4+
echo 'Error: docker-compose is not installed.' >&2
5+
exit 1
6+
fi
7+
8+
domains=(example.org www.example.org)
9+
rsa_key_size=4096
10+
data_path="./certbot"
11+
email="youremail@xxx.com" # Adding a valid address is strongly recommended
12+
staging=0 # Set to 1 if you're testing your setup to avoid hitting request limits
13+
14+
if [ -d "$data_path" ]; then
15+
read -p "Existing data found for $domains. Continue and replace existing certificate? (y/N) " decision
16+
if [ "$decision" != "Y" ] && [ "$decision" != "y" ]; then
17+
exit
18+
fi
19+
fi
20+
21+
22+
if [ ! -e "$data_path/conf/options-ssl-nginx.conf" ] || [ ! -e "$data_path/conf/ssl-dhparams.pem" ]; then
23+
echo "### Downloading recommended TLS parameters ..."
24+
mkdir -p "$data_path/conf"
25+
curl -s https://raw.githubusercontent.com/certbot/certbot/master/certbot-nginx/certbot_nginx/_internal/tls_configs/options-ssl-nginx.conf > "$data_path/conf/options-ssl-nginx.conf"
26+
curl -s https://raw.githubusercontent.com/certbot/certbot/master/certbot/certbot/ssl-dhparams.pem > "$data_path/conf/ssl-dhparams.pem"
27+
echo
28+
fi
29+
30+
echo "### Creating dummy certificate for $domains ..."
31+
path="/etc/letsencrypt/live/$domains"
32+
mkdir -p "$data_path/conf/live/$domains"
33+
docker-compose run --rm --entrypoint "\
34+
openssl req -x509 -nodes -newkey rsa:$rsa_key_size -days 1\
35+
-keyout '$path/privkey.pem' \
36+
-out '$path/fullchain.pem' \
37+
-subj '/CN=localhost'" certbot
38+
echo
39+
40+
41+
echo "### Starting nginx ..."
42+
docker-compose up --force-recreate -d nginx
43+
echo
44+
45+
echo "### Deleting dummy certificate for $domains ..."
46+
docker-compose run --rm --entrypoint "\
47+
rm -Rf /etc/letsencrypt/live/$domains && \
48+
rm -Rf /etc/letsencrypt/archive/$domains && \
49+
rm -Rf /etc/letsencrypt/renewal/$domains.conf" certbot
50+
echo
51+
52+
53+
echo "### Requesting Let's Encrypt certificate for $domains ..."
54+
#Join $domains to -d args
55+
domain_args=""
56+
for domain in "${domains[@]}"; do
57+
domain_args="$domain_args -d $domain"
58+
done
59+
60+
# Select appropriate email arg
61+
case "$email" in
62+
"") email_arg="--register-unsafely-without-email" ;;
63+
*) email_arg="--email $email" ;;
64+
esac
65+
66+
# Enable staging mode if needed
67+
if [ $staging != "0" ]; then staging_arg="--staging"; fi
68+
69+
docker-compose run --rm --entrypoint "\
70+
certbot certonly --webroot -w /var/www/certbot \
71+
$staging_arg \
72+
$email_arg \
73+
$domain_args \
74+
--rsa-key-size $rsa_key_size \
75+
--agree-tos \
76+
--force-renewal" certbot
77+
echo
78+
79+
echo "### Reloading nginx ..."
80+
docker-compose exec nginx nginx -s reload

‎nginx.localhost/app.conf

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
server {
2+
listen 80;
3+
server_name example.org www.example.org;
4+
server_tokens off;
5+
6+
location /.well-known/acme-challenge/ {
7+
root /var/www/certbot;
8+
}
9+
10+
#location / {
11+
# return 301 https://$host$request_uri;
12+
#}
13+
}
14+
15+
server {
16+
listen 443 ssl;
17+
server_name example.org www.example.org;
18+
server_tokens off;
19+
20+
ssl_certificate /etc/letsencrypt/live/example.org/fullchain.pem;
21+
ssl_certificate_key /etc/letsencrypt/live/example.org/privkey.pem;
22+
include /etc/letsencrypt/options-ssl-nginx.conf;
23+
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
24+
25+
location / {
26+
proxy_pass http://example.org;
27+
proxy_set_header Host $http_host;
28+
proxy_set_header X-Real-IP $remote_addr;
29+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
30+
}
31+
}

‎nginx/app.conf

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
server {
2+
listen 80;
3+
server_name example.org www.example.org;
4+
5+
location ~ /.well-known/acme-challenge/ {
6+
allow all;
7+
root /var/www/certbot;
8+
}
9+
10+
#location / {
11+
# return 301 https://$host$request_uri;
12+
#}
13+
14+
if ($host = www.example.org) {
15+
return 301 https://$host$request_uri;
16+
}
17+
18+
19+
if ($host = example.org) {
20+
return 301 https://$host$request_uri;
21+
}
22+
23+
}
24+
25+
server {
26+
# Listen to HTTPS on 443 and allow HTTP/2
27+
listen 443 ssl http2 default;
28+
29+
server_name example.org www.example.org;
30+
31+
ssl_certificate /etc/letsencrypt/live/example.org/fullchain.pem;
32+
ssl_certificate_key /etc/letsencrypt/live/example.org/privkey.pem;
33+
34+
# Improve HTTPS performance with session resumption
35+
ssl_session_timeout 1d;
36+
ssl_session_cache shared:SSL:50m;
37+
ssl_session_tickets off;
38+
39+
# Enable server-side protection against BEAST attacks
40+
ssl_protocols TLSv1.2;
41+
ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
42+
ssl_prefer_server_ciphers on;
43+
44+
# Diffie-Hellman parameter for DHE ciphersuites
45+
# $ openssl dhparam -out ssl-dhparams.pem 4096
46+
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
47+
48+
# Enable OCSP stapling (http://blog.mozilla.org/security/2013/07/29/ocsp-stapling-in-firefox)
49+
# uses Google DNS servers
50+
ssl_stapling on;
51+
ssl_stapling_verify on;
52+
ssl_trusted_certificate /etc/letsencrypt/live/example.org/fullchain.pem;
53+
resolver 8.8.8.8 8.8.4.4 valid=300s;
54+
resolver_timeout 5s;
55+
56+
# Logging in a container
57+
access_log /dev/stdout;
58+
error_log stderr error;
59+
error_log /dev/stdout info;
60+
61+
# Document Root
62+
root /var/www/public/;
63+
64+
# Directory Indexes
65+
index index.php index.html index.htm;
66+
67+
# Character Set
68+
charset utf-8;
69+
70+
# TODO: Compression, interpreters, websocket proxies, logging, XSS headers, ...
71+
72+
# Location
73+
location / {
74+
try_files $uri $uri/ /index.php;
75+
}
76+
77+
# Error Pages
78+
error_page 404 /404.html;
79+
error_page 500 502 503 504 /50x.html;
80+
81+
# Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
82+
#
83+
location ~ \.php$ {
84+
try_files $uri =404;
85+
fastcgi_split_path_info ^(.+\.php)(/.+)$;
86+
fastcgi_pass php:9000;
87+
fastcgi_index index.php;
88+
include fastcgi_params;
89+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
90+
fastcgi_param PATH_INFO $fastcgi_path_info;
91+
}
92+
93+
# Deny access to . files, for security
94+
#
95+
location ~ /\. {
96+
log_not_found off;
97+
deny all;
98+
}
99+
100+
# Block access to .htaccess
101+
location ~ \.htaccess {
102+
deny all;
103+
}
104+
}

‎php/Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM php:8-fpm-alpine
2+
LABEL Maintainer="Tobing <lumban.tobing.m@gmail.com>" \
3+
4+
RUN apk update && apk add curl && \
5+
curl -sS https://getcomposer.org/installer | php \
6+
&& chmod +x composer.phar && mv composer.phar /usr/local/bin/composer
7+
8+
RUN apk --no-cache add --virtual .build-deps $PHPIZE_DEPS \
9+
&& apk --no-cache add --virtual .ext-deps icu-dev libmcrypt-dev freetype-dev \
10+
libjpeg-turbo-dev libpng-dev libxpm-dev libwebp-dev libxml2-dev msmtp bash openssl-dev libpq-dev libzip-dev pkgconfig \
11+
&& docker-php-source extract \
12+
&& docker-php-ext-configure intl \
13+
&& docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp --with-xpm \
14+
&& docker-php-ext-install gd intl pdo pdo_mysql mysqli pgsql pdo_pgsql zip opcache \
15+
&& docker-php-ext-enable opcache \
16+
&& docker-php-source delete \
17+
&& apk del .build-deps

‎public/index.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
$mysqlservername = "mysql";
4+
$mysqlusername = "root";
5+
$mysqlpassword = "0123456789";
6+
7+
try {
8+
$conn = new PDO("mysql:host=$mysqlservername;dbname=dbname", $mysqlusername, $mysqlpassword);
9+
// set the PDO error mode to exception
10+
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
11+
echo "MySQL connection to ".$mysqlservername." success";
12+
} catch(PDOException $e) {
13+
echo "MySQL connection to ".$mysqlservername." failed: " . $e->getMessage();
14+
}
15+
16+
17+
$pgsqlservername = "pgsql";
18+
$pgsqlusername = "postgres";
19+
$pgsqlpassword = "example";
20+
21+
echo "<br>";
22+
echo "<br>";
23+
24+
try {
25+
$conn = new PDO("pgsql:host=$pgsqlservername;dbname=postgres", $pgsqlusername, $pgsqlpassword);
26+
// set the PDO error mode to exception
27+
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
28+
echo "PostgreSQL connection to ".$pgsqlservername." success";
29+
} catch(PDOException $e) {
30+
echo "PostgreSQL connection to ".$pgsqlservername." failed: " . $e->getMessage();
31+
}
32+
33+
echo "<br>";
34+
echo "<br>";
35+
36+
phpinfo();
37+
38+
/*
39+
$url = "https://example.org";
40+
$orignal_parse = parse_url($url, PHP_URL_HOST);
41+
$get = stream_context_create(array("ssl" => array("capture_peer_cert" => TRUE)));
42+
$read = stream_socket_client("ssl://".$orignal_parse.":443", $errno, $errstr,
43+
30, STREAM_CLIENT_CONNECT, $get);
44+
$cert = stream_context_get_params($read);
45+
$certinfo = openssl_x509_parse($cert['options']['ssl']['peer_certificate']);
46+
47+
$valid_from = date(DATE_RFC2822,$certinfo['validFrom_time_t']);
48+
$valid_to = date(DATE_RFC2822,$certinfo['validTo_time_t']);
49+
50+
echo '<pre>';
51+
echo ($certinfo["issuer"]["O"]);
52+
echo "\r\n";
53+
echo "Valid From: ".$valid_from."<br>";
54+
echo "Valid To:".$valid_to."<br>";
55+
echo '<pre>';
56+
*/

‎public/test.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<html>
2+
<body>
3+
<h1>Nginx with Let's Encrypt</h1>
4+
</body>
5+
</html>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /