I have a Synology NAS DS1813+ and I wish to install Nextcloud into it and I managed to do it by using Docker. Note that it will be available just in local network.
Next, I wish to secure it by using SSL, however I could not do it as 443 is already taken by Synology. Thus, I try to use jwilder/nginx-proxy reverse proxy. However, I receive the error : 400 Bad Request The plain HTTP request was sent to HTTPS port. I access it by using (https://cavrnas:446/. NextCloud can be accessed without https by using http://cavrnas:8080, Synology admin web UI can be accessed by using http://cavrnas:5000 or https://cavrnas:5001).
Note that the certificate is a self-signed one genereated by using paulczar/omgwtfssl. As 443 is already taken by Synology, so I tried to listen to port 446 for SSL instead. The following is my docker-compose.yml file (based on https://github.com/nextcloud/docker/tree/master/.examples/docker-compose/with-nginx-proxy/mariadb/apache) :
version: '3'
services:
db:
image: mariadb
command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
restart: always
container_name : nextcloud_db
volumes:
- /volume1/NextCloud_Data/MariaDB:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=123
env_file:
- db.env
app:
build: .
restart: always
container_name : nextcloud_app
volumes:
- /volume1/NextCloud_Data/main:/var/www/html
- /volume1/NextCloud_Data/apps:/var/www/html/custom_apps
- /volume1/NextCloud_Data/config:/var/www/html/config
- /volume1/NextCloud_Data/data:/var/www/html/data
- /volume1/NextCloud_Data/theme:/var/www/html/themes/
- /volume1/NextCloud_Data/db:/var/lib/mysql
- /volume1/NextCloud_Data/apache2_log:/var/log/apache2
environment:
- VIRTUAL_HOST=cavrnas.local
- MYSQL_HOST=db
- CERT_NAME=cavrnas.local
env_file:
- db.env
depends_on:
- db
- certs
networks:
- proxy-tier
- default
proxy:
build: ./proxy
restart: always
container_name : nextcloud_proxy
depends_on :
- certs
ports:
- 81:80
- 446:443
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- /volume1/NextCloud_Data/SSL:/etc/nginx/certs
- /volume1/NextCloud_Data/nginx:/etc/nginx/conf.d
- /volume1/NextCloud_Data/nginx_log:/var/log/nginx
environment:
- SSL_POLICY=Mozilla-Modern
- HTTPS_METHOD=nohttp
- VIRTUAL_PORT=446
networks:
- proxy-tier
certs:
container_name : nextcloud_cert
environment:
- CA_SUBJECT=ntu
- CA_CERT=/certs/cavrnas.local.crt
- CA_KEY=/certs/cavrnas.local.key
- CA_EXPIRE=3650
- SSL_SIZE=2048
- SSL_SUBJECT=cavrnas.local
image: paulczar/omgwtfssl
volumes:
- /volume1/NextCloud_Data/SSL:/certs
networks:
- proxy-tier
volumes:
db:
nextcloud:
certs:
vhost.d:
html:
networks:
proxy-tier:
And the following is the content of default.conf.
# If we receive X-Forwarded-Proto, pass it through; otherwise, pass along the
# scheme used to connect to this server
map $http_x_forwarded_proto $proxy_x_forwarded_proto {
default $http_x_forwarded_proto;
'' $scheme;
}
# If we receive X-Forwarded-Port, pass it through; otherwise, pass along the
# server port the client connected to
map $http_x_forwarded_port $proxy_x_forwarded_port {
default $http_x_forwarded_port;
'' $server_port;
}
# If we receive Upgrade, set Connection to "upgrade"; otherwise, delete any
# Connection header that may have been passed to this server
map $http_upgrade $proxy_connection {
default upgrade;
'' close;
}
# Apply fix for very long server names
server_names_hash_bucket_size 128;
# Default dhparam
ssl_dhparam /etc/nginx/dhparam/dhparam.pem;
# Set appropriate X-Forwarded-Ssl header
map $scheme $proxy_x_forwarded_ssl {
default off;
https on;
}
gzip_types text/plain text/css application/javascript application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
log_format vhost '$host $remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent"';
access_log off;
ssl_protocols TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers off;
resolver 127.0.0.11;
# HTTP 1.1 support
proxy_http_version 1.1;
proxy_buffering off;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $proxy_connection;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $proxy_x_forwarded_proto;
proxy_set_header X-Forwarded-Ssl $proxy_x_forwarded_ssl;
proxy_set_header X-Forwarded-Port $proxy_x_forwarded_port;
# Mitigate httpoxy attack (see README for details)
proxy_set_header Proxy "";
server {
server_name _; # This is just an invalid value which will never trigger on a real hostname.
listen 80;
access_log /var/log/nginx/access.log vhost;
return 503;
}
# cavrnas.local
upstream cavrnas.local {
# Cannot connect to network of this container
server 127.0.0.1 down;
## Can be connected with "docker-compose_proxy-tier" network
# nextcloud_app
server 172.18.0.2:80;
}
server {
server_name cavrnas.local;
listen 80 ;
access_log /var/log/nginx/access.log vhost;
return 301 https://$host$request_uri;
}
server {
server_name cavrnas.local;
listen 443 ssl http2 ;
access_log /var/log/nginx/access.log vhost;
ssl_session_timeout 5m;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets off;
ssl_certificate /etc/nginx/certs/cavrnas.local.crt;
ssl_certificate_key /etc/nginx/certs/cavrnas.local.key;
add_header Strict-Transport-Security "max-age=31536000" always;
location / {
proxy_pass http://cavrnas.local;
}
}
Note that it can be also accessed by using cavrnas.local. (Maybe because the server name setting in the Synology is cavrnas. If I ping the IP address, it gives me cavrnas.local).
I see that some people recommend putting this in the .conf file for this kind of error.
error_page 497 https://$host:$server_port$request_uri;
However, when I do this, it is redirected to the NAS Web UI at https://cavrnas:5001.
Does anybody have solution for this ?
Thanks!