This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

NGINX

  • Loading branch information...
cadecairos committed Apr 27, 2018
1 parent 3c37140 commit d4a47ba1847bda9e275070b0622eeb71e18e1a62
Showing with 58 additions and 19 deletions.
  1. +6 −5 Dockerfile
  2. +9 −0 run.R
  3. +31 −8 shiny-server.conf
  4. +12 −6 shiny-server.sh
View
@@ -1,6 +1,6 @@
FROM rocker/shiny
FROM r-base:latest
MAINTAINER Vojtech Sedlak (vojtech@mozillafoundation.org)
LABEL maintainers="Vojtech Sedlak (vojtech@mozillafoundation.org), Christopher DeCairos (cade@mozillafoundation.org)"
# install R package dependencies
RUN apt-get update && apt-get install -y \
@@ -14,6 +14,7 @@ RUN apt-get update && apt-get install -y \
libssl-dev \
libxml2 \
libxml2-dev \
nginx \
## clean up
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/
@@ -23,8 +24,8 @@ RUN R -e "install.packages(c('tidyverse', 'stringr', 'ggthemes', 'scales','shiny
## clean up
&& rm -rf /tmp/downloaded_packages/ /tmp/*.rds
COPY . /srv/shiny-server/shinysurvey/
COPY . /app/
RUN cp /srv/shiny-server/shinysurvey/shiny-server.conf /etc/shiny-server/shiny-server.conf
WORKDIR /app
CMD ["/srv/shiny-server/shinysurvey/shiny-server.sh"]
CMD ["/app/shiny-server.sh"]
View
9 run.R
@@ -0,0 +1,9 @@
library(shiny)
port <- Sys.getenv('R_PORT')
shiny::runApp(
appDir = getwd(),
host = '0.0.0.0',
port = as.numeric(port)
)
View
@@ -1,13 +1,36 @@
run_as $USER;
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream shinysurvey {
server 0.0.0.0:$R_PORT;
}
server {
listen $PORT;
listen $PORT;
server_name $HOSTNAME;
if ($http_x_forwarded_proto != 'https') {
return 301 https://$host$request_uri;
}
location / {
proxy_pass http://shinysurvey;
frame_options deny;
add_header Content-Security-Policy "default-src 'none'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self'; connect-src 'self'; media-src 'self'; upgrade-insecure-requests; block-all-mixed-content; reflected-xss block; base-uri https://$host;" always;
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always;
add_header X-Content-Type-Options nosniff always;
add_header X-Frame-Options deny always;
add_header X-XSS-Protection "1; mode=block" always;
add_header Referrer-Policy "no-referrer";
}
location / {
run_as $USER;
app_dir /srv/shiny-server/shinysurvey;
log_dir /var/log/shiny-server;
}
location /websocket {
proxy_pass http://shinysurvey;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
View
@@ -1,13 +1,19 @@
#!/bin/sh
# Make sure the directory for individual app logs exists
mkdir -p /var/log/shiny-server
sed -i -e "s/\$PORT/$PORT/g" /etc/shiny-server/shiny-server.conf
export R_PORT=`expr $PORT + 1`
USER=`whoami`
sed -i -e "s/\$PORT/$PORT/g" /app/shiny-server.conf
sed -i -e "s/\$R_PORT/$R_PORT/g" /app/shiny-server.conf
sed -i -e "s/\$HOSTNAME/$HOSTNAME/g" /app/shiny-server.conf
mkhomedir_helper $USER
sed -i -e "s/\$USER/$USER/g" /etc/shiny-server/shiny-server.conf
ln -s /app/shiny-server.conf /etc/nginx/sites-enabled/shiny-server.conf
exec shiny-server 2>&1
echo "Starting NGINX"
rm /etc/nginx/sites-enabled/default
service nginx start
exec /usr/bin/R --no-save --quiet --slave --file=/app/run.R

0 comments on commit d4a47ba

Please sign in to comment.