Created
October 3, 2017 09:33
-
-
Save allenaven/72cb7276a2fe4e1faf07d43fe568653f to your computer and use it in GitHub Desktop.
Nginx config files to serve RStudio Server behind a subdomain and proxy. Oh and TLS too. Ubuntu Xenial, LetsEncrypt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Default server configuration | |
## /etc/nginx/sites-available/inductive-pw.conf | |
## simlink this to /etc/nginx/sites-enabled | |
server { | |
listen 80 default_server; | |
listen 443 ssl; # managed by Certbot | |
server_name inductive.pw www.inductive.pw; | |
ssl_certificate /etc/letsencrypt/live/inductive.pw/fullchain.pem; # managed by Certbot | |
ssl_certificate_key /etc/letsencrypt/live/inductive.pw/privkey.pem; # managed by Certbot | |
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot | |
if ($scheme != "https") { | |
return 301 https://$host$request_uri; | |
} # managed by Certbot | |
root /var/www/html; | |
index index.html index.htm index.php index.nginx-debian.html; | |
location / { | |
try_files $uri $uri/ =404; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## /etc/nginx/nginx.conf | |
user www-data; | |
worker_processes auto; | |
pid /run/nginx.pid; | |
events { | |
worker_connections 1024; | |
# multi_accept on; | |
} | |
http { | |
## | |
# Basic Settings | |
## | |
sendfile on; | |
tcp_nopush on; | |
tcp_nodelay on; | |
keepalive_timeout 55; | |
types_hash_max_size 2048; | |
server_tokens off; | |
# server_names_hash_bucket_size 64; | |
# server_name_in_redirect off; | |
include /etc/nginx/mime.types; | |
default_type application/octet-stream; | |
## | |
# SSL Settings | |
## | |
ssl_session_cache shared:SSL:10m; | |
ssl_session_timeout 20m; | |
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; | |
ssl_prefer_server_ciphers on; | |
map $http_upgrade $connection_upgrade { | |
default upgrade; | |
'' close; | |
} | |
## | |
# Logging Settings | |
## | |
access_log /var/log/nginx/access.log; | |
error_log /var/log/nginx/error.log; | |
## | |
# Gzip Settings | |
## | |
gzip off; | |
gzip_disable "msie6"; | |
# 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/sites-enabled/*; | |
include /etc/nginx/conf.d/*.conf; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Server config for subdomain serving RStudio Server | |
## /etc/nginx/sites-available/rs-inductive-pw.conf | |
## simlink this to /etc/nginx/sites-enabled | |
server { | |
listen 80; | |
listen 443 ssl; # managed by Certbot | |
server_name rs.inductive.pw www.rs.inductive.pw; | |
ssl_certificate /etc/letsencrypt/live/inductive.pw/fullchain.pem; # managed by Certbot | |
ssl_certificate_key /etc/letsencrypt/live/inductive.pw/privkey.pem; # managed by Certbot | |
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot | |
# Redirect non-https traffic to https | |
if ($scheme != "https") { | |
return 301 https://$host$request_uri; | |
} # managed by Certbot | |
location / { | |
rewrite ^/(.*)$ /$1 break; | |
proxy_pass http://127.0.0.1:8787; | |
proxy_redirect http://127.0.0.1:8787/ $scheme://$host/; | |
proxy_http_version 1.1; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection $connection_upgrade; | |
proxy_read_timeout 20d; | |
} | |
location ^~ /.well-known/{ | |
allow all; | |
root /var/www/html; | |
log_not_found off; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment