2021-11-23 05:52:09 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
set -o nounset
|
|
|
|
|
|
2023-08-09 16:18:58 +00:00
|
|
|
use_https="$1"
|
|
|
|
|
custom_domain="${2:-_}"
|
|
|
|
|
|
|
|
|
|
if [[ $use_https == 1 ]]; then
|
|
|
|
|
# By default, container will use the auto-generate certificate by Let's Encrypt
|
|
|
|
|
ssl_cert_path="/etc/letsencrypt/live/$custom_domain/fullchain.pem"
|
|
|
|
|
ssl_key_path="/etc/letsencrypt/live/$custom_domain/privkey.pem"
|
|
|
|
|
|
|
|
|
|
# In case of existing custom certificate, container will use them to configure SSL
|
|
|
|
|
if [[ -e "/appsmith-stacks/ssl/fullchain.pem" ]] && [[ -e "/appsmith-stacks/ssl/privkey.pem" ]]; then
|
|
|
|
|
ssl_cert_path="/appsmith-stacks/ssl/fullchain.pem"
|
|
|
|
|
ssl_key_path="/appsmith-stacks/ssl/privkey.pem"
|
|
|
|
|
fi
|
2021-11-23 05:52:09 +00:00
|
|
|
fi
|
|
|
|
|
|
2023-08-08 14:56:00 +00:00
|
|
|
additional_downstream_headers='
|
|
|
|
|
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options
|
|
|
|
|
add_header X-Content-Type-Options "nosniff";
|
|
|
|
|
'
|
|
|
|
|
|
2021-11-23 05:52:09 +00:00
|
|
|
cat <<EOF
|
2021-11-23 10:20:37 +00:00
|
|
|
map \$http_x_forwarded_proto \$origin_scheme {
|
|
|
|
|
default \$http_x_forwarded_proto;
|
|
|
|
|
'' \$scheme;
|
2021-11-23 08:17:44 +00:00
|
|
|
}
|
2022-10-14 01:00:27 +00:00
|
|
|
|
|
|
|
|
map \$http_x_forwarded_host \$origin_host {
|
|
|
|
|
default \$http_x_forwarded_host;
|
|
|
|
|
'' \$host;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-31 04:48:32 +00:00
|
|
|
map \$http_forwarded \$final_forwarded {
|
|
|
|
|
default '\$http_forwarded, host=\$host;proto=\$scheme';
|
|
|
|
|
'' '';
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-24 08:17:25 +00:00
|
|
|
# redirect log to stdout for supervisor to capture
|
|
|
|
|
access_log /dev/stdout;
|
2021-11-23 08:17:44 +00:00
|
|
|
|
2023-08-07 09:54:22 +00:00
|
|
|
server_tokens off;
|
|
|
|
|
|
2021-11-23 05:52:09 +00:00
|
|
|
server {
|
2023-08-09 16:18:58 +00:00
|
|
|
|
|
|
|
|
$(
|
|
|
|
|
if [[ $use_https == 1 ]]; then
|
|
|
|
|
echo "
|
|
|
|
|
listen 80;
|
|
|
|
|
server_name $custom_domain;
|
|
|
|
|
return 301 https://\$host\$request_uri;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
server {
|
|
|
|
|
listen 443 ssl http2;
|
|
|
|
|
server_name _;
|
|
|
|
|
ssl_certificate $ssl_cert_path;
|
|
|
|
|
ssl_certificate_key $ssl_key_path;
|
|
|
|
|
include /appsmith-stacks/data/certificate/conf/options-ssl-nginx.conf;
|
|
|
|
|
ssl_dhparam /appsmith-stacks/data/certificate/conf/ssl-dhparams.pem;
|
|
|
|
|
"
|
|
|
|
|
else
|
|
|
|
|
echo "
|
2022-03-24 07:47:36 +00:00
|
|
|
listen ${PORT:-80} default_server;
|
2023-08-09 16:18:58 +00:00
|
|
|
server_name $custom_domain;
|
|
|
|
|
"
|
|
|
|
|
fi
|
|
|
|
|
)
|
2021-11-23 05:52:09 +00:00
|
|
|
|
2023-02-20 15:04:02 +00:00
|
|
|
client_max_body_size 150m;
|
2021-11-23 05:52:09 +00:00
|
|
|
|
|
|
|
|
gzip on;
|
2022-08-05 11:10:38 +00:00
|
|
|
gzip_types *;
|
|
|
|
|
|
2021-11-23 05:52:09 +00:00
|
|
|
root /opt/appsmith/editor;
|
2022-09-26 04:11:38 +00:00
|
|
|
index index.html;
|
|
|
|
|
error_page 404 /;
|
2021-11-23 08:17:44 +00:00
|
|
|
|
2022-07-21 07:33:35 +00:00
|
|
|
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/frame-ancestors
|
2022-08-02 10:11:52 +00:00
|
|
|
add_header Content-Security-Policy "frame-ancestors ${APPSMITH_ALLOWED_FRAME_ANCESTORS-'self' *}";
|
2022-07-21 07:33:35 +00:00
|
|
|
|
2023-08-08 14:56:00 +00:00
|
|
|
$additional_downstream_headers
|
|
|
|
|
|
2021-11-23 05:52:09 +00:00
|
|
|
location /.well-known/acme-challenge/ {
|
|
|
|
|
root /appsmith-stacks/data/certificate/certbot;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-24 07:47:36 +00:00
|
|
|
location = /supervisor {
|
|
|
|
|
return 301 /supervisor/;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
location /supervisor/ {
|
2023-08-09 16:18:58 +00:00
|
|
|
proxy_http_version 1.1;
|
|
|
|
|
proxy_buffering off;
|
2022-03-24 07:47:36 +00:00
|
|
|
proxy_max_temp_file_size 0;
|
2023-08-09 16:18:58 +00:00
|
|
|
proxy_redirect off;
|
2022-07-21 07:33:35 +00:00
|
|
|
|
2022-10-14 01:00:27 +00:00
|
|
|
proxy_set_header Host \$http_host/supervisor/;
|
|
|
|
|
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
|
|
|
|
|
proxy_set_header X-Forwarded-Proto \$origin_scheme;
|
|
|
|
|
proxy_set_header X-Forwarded-Host \$origin_host;
|
|
|
|
|
proxy_set_header Connection "";
|
2022-07-21 07:33:35 +00:00
|
|
|
|
2022-03-24 07:47:36 +00:00
|
|
|
proxy_pass http://localhost:9001/;
|
|
|
|
|
|
|
|
|
|
auth_basic "Protected";
|
|
|
|
|
auth_basic_user_file /etc/nginx/passwords;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-23 08:17:44 +00:00
|
|
|
proxy_set_header X-Forwarded-Proto \$origin_scheme;
|
2023-07-31 04:48:32 +00:00
|
|
|
proxy_set_header X-Forwarded-Host \$origin_host;
|
|
|
|
|
proxy_set_header Forwarded \$final_forwarded;
|
2021-11-23 05:52:09 +00:00
|
|
|
|
|
|
|
|
location / {
|
2023-04-19 12:50:59 +00:00
|
|
|
try_files /loading.html \$uri /index.html =404;
|
2021-11-23 05:52:09 +00:00
|
|
|
}
|
|
|
|
|
|
2023-04-19 01:12:01 +00:00
|
|
|
location ~ ^/static/(js|css|media)\b {
|
|
|
|
|
# Files in these folders are hashed, so we can set a long cache time.
|
|
|
|
|
add_header Cache-Control "max-age=31104000, immutable"; # 360 days
|
2023-08-08 14:56:00 +00:00
|
|
|
$additional_downstream_headers
|
2023-06-06 08:21:26 +00:00
|
|
|
access_log off;
|
2023-04-19 01:12:01 +00:00
|
|
|
}
|
|
|
|
|
|
2022-09-26 04:11:38 +00:00
|
|
|
# If the path has an extension at the end, then respond with 404 status if the file not found.
|
2022-10-14 07:53:09 +00:00
|
|
|
location ~ ^/(?!supervisor/).*\.[a-z]+$ {
|
2022-09-26 04:11:38 +00:00
|
|
|
try_files \$uri =404;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-23 05:52:09 +00:00
|
|
|
location /api {
|
2023-07-06 12:31:26 +00:00
|
|
|
proxy_read_timeout ${APPSMITH_SERVER_TIMEOUT:-60};
|
|
|
|
|
proxy_send_timeout ${APPSMITH_SERVER_TIMEOUT:-60};
|
2021-11-23 05:52:09 +00:00
|
|
|
proxy_pass http://localhost:8080;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
location /oauth2 {
|
|
|
|
|
proxy_pass http://localhost:8080;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
location /login {
|
|
|
|
|
proxy_pass http://localhost:8080;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
location /rts {
|
2023-02-15 01:36:02 +00:00
|
|
|
proxy_pass http://localhost:${APPSMITH_RTS_PORT:-8091};
|
2021-11-23 05:52:09 +00:00
|
|
|
proxy_http_version 1.1;
|
|
|
|
|
proxy_set_header Host \$host;
|
|
|
|
|
proxy_set_header Connection 'upgrade';
|
|
|
|
|
proxy_set_header Upgrade \$http_upgrade;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
EOF
|