Skip to content

Commit

Permalink
add nginx to dockerfunc and fun aliases
Browse files Browse the repository at this point in the history
Signed-off-by: Jessica Frazelle <[email protected]>
  • Loading branch information
jessfraz committed Jul 28, 2015
1 parent 1f57132 commit c32c7be
Show file tree
Hide file tree
Showing 7 changed files with 274 additions and 10 deletions.
65 changes: 56 additions & 9 deletions .dockerfunc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,39 @@ relies_on(){
fi
done
}
# creates an nginx config for a local route
nginx_config(){
server=$1
route=$2

cat >${HOME}/.nginx/conf.d/${server}.conf <<-EOF
upstream ${server} { server ${route}; }
server {
server_name ${server};
location / {
proxy_pass http://${server};
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host \$http_host;
proxy_set_header X-Forwarded-Proto \$scheme;
proxy_set_header X-Forwarded-For \$remote_addr;
proxy_set_header X-Forwarded-Port \$server_port;
proxy_set_header X-Request-Start \$msec;
}
}
EOF

# restart nginx
docker restart nginx

# add host to /etc/hosts
sudo hostess add $server ${route%:*}

# open browser
browser-exec "http://${server}"
}

#
# Container Aliases
Expand Down Expand Up @@ -55,11 +88,13 @@ cadvisor(){
--name cadvisor \
google/cadvisor

browser-exec "http://127.0.0.1:1212"
nginx_config cadvisor 127.0.0.1:1212
}
chrome(){
del_stopped chrome

# one day remove /etc/hosts bind mount when effing
# overlay support inotify, such bullshit
docker run -d \
--memory 5gb \
--net host \
Expand All @@ -70,6 +105,7 @@ chrome(){
-v $HOME/Pictures:/root/Pictures \
-v $HOME/Torrents:/root/Torrents \
-v $HOME/.chrome:/data \
-v /etc/hosts:/etc/hosts \
--device /dev/snd \
--device /dev/dri \
--device /dev/video0 \
Expand All @@ -85,16 +121,16 @@ cloudapp(){
--log-driver none \
jess/cloudapp "$@"
}
documentserver(){
del_stopped documentserver
docserver(){
del_stopped docserver

docker run --rm -it \
-p 1234:80 \
-v $HOME/slides:/slides \
--name documentserver \
onlyoffice/documentserver
--name docserver \
onlyoffice/docserver

browser-exec "http://127.0.0.1:1234/"
nginx_config docserver 127.0.0.1:1234
}
firefox(){
del_stopped firefox
Expand Down Expand Up @@ -283,6 +319,19 @@ nes(){
--name nes \
jess/nes /games/${game}.rom
}
nginx(){
del_stopped nginx

docker run -d \
-v $HOME/.nginx:/etc/nginx \
--net host \
--name nginx \
nginx

# add domain to hosts & open nginx
sudo hostess add jess 127.0.0.1
browser-exec "http://jess"
}
notify_osd(){
del_stopped notify-osd

Expand All @@ -309,13 +358,11 @@ pandoc(){
local rfile=$(readlink -m "/$(basename $file)")
local args=${@:1:${#@}-1}

set -x
docker run --rm \
-v ${lfile}:${rfile} \
-v /tmp:/tmp \
--name pandoc \
jess/pandoc ${args} ${rfile}
set +x
}
pms(){
del_stopped pms
Expand Down Expand Up @@ -499,7 +546,7 @@ transmission(){
--name transmission \
jess/transmission

browser-exec "http://127.0.0.1:9091/transmission"
nginx_config transmission 127.0.0.1:9091
}
vagrant(){
del_stopped vagrant
Expand Down
8 changes: 8 additions & 0 deletions .nginx/conf.d/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
server {
listen [::]:80;
listen 80;
server_name localhost;
server_name jess;

return 301 https://blog.jessfraz.com;
}
16 changes: 16 additions & 0 deletions .nginx/conf.d/syncthing.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
upstream syncthing { server 127.0.0.1:8080; }
server {
server_name syncthing;

location / {
proxy_pass http://syncthing;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Request-Start $msec;
}
}
16 changes: 16 additions & 0 deletions .nginx/conf.d/transmission.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
upstream transmission { server 127.0.0.1:9091; }
server {
server_name transmission;

location / {
proxy_pass http://transmission;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Request-Start $msec;
}
}
89 changes: 89 additions & 0 deletions .nginx/mime.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@

types {
text/html html htm shtml;
text/css css;
text/xml xml;
image/gif gif;
image/jpeg jpeg jpg;
application/javascript js;
application/atom+xml atom;
application/rss+xml rss;

text/mathml mml;
text/plain txt;
text/vnd.sun.j2me.app-descriptor jad;
text/vnd.wap.wml wml;
text/x-component htc;

image/png png;
image/tiff tif tiff;
image/vnd.wap.wbmp wbmp;
image/x-icon ico;
image/x-jng jng;
image/x-ms-bmp bmp;
image/svg+xml svg svgz;
image/webp webp;

application/font-woff woff;
application/java-archive jar war ear;
application/json json;
application/mac-binhex40 hqx;
application/msword doc;
application/pdf pdf;
application/postscript ps eps ai;
application/rtf rtf;
application/vnd.apple.mpegurl m3u8;
application/vnd.ms-excel xls;
application/vnd.ms-fontobject eot;
application/vnd.ms-powerpoint ppt;
application/vnd.wap.wmlc wmlc;
application/vnd.google-earth.kml+xml kml;
application/vnd.google-earth.kmz kmz;
application/x-7z-compressed 7z;
application/x-cocoa cco;
application/x-java-archive-diff jardiff;
application/x-java-jnlp-file jnlp;
application/x-makeself run;
application/x-perl pl pm;
application/x-pilot prc pdb;
application/x-rar-compressed rar;
application/x-redhat-package-manager rpm;
application/x-sea sea;
application/x-shockwave-flash swf;
application/x-stuffit sit;
application/x-tcl tcl tk;
application/x-x509-ca-cert der pem crt;
application/x-xpinstall xpi;
application/xhtml+xml xhtml;
application/xspf+xml xspf;
application/zip zip;

application/octet-stream bin exe dll;
application/octet-stream deb;
application/octet-stream dmg;
application/octet-stream iso img;
application/octet-stream msi msp msm;

application/vnd.openxmlformats-officedocument.wordprocessingml.document docx;
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx;
application/vnd.openxmlformats-officedocument.presentationml.presentation pptx;

audio/midi mid midi kar;
audio/mpeg mp3;
audio/ogg ogg;
audio/x-m4a m4a;
audio/x-realaudio ra;

video/3gpp 3gpp 3gp;
video/mp2t ts;
video/mp4 mp4;
video/mpeg mpeg mpg;
video/quicktime mov;
video/webm webm;
video/x-flv flv;
video/x-m4v m4v;
video/x-mng mng;
video/x-ms-asf asx asf;
video/x-ms-wmv wmv;
video/x-msvideo avi;
}
85 changes: 85 additions & 0 deletions .nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
user nginx;
worker_processes 1;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;


events {
worker_connections 1024;
}


http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

# Update charset_types due to updated mime.types
charset_types text/xml text/plain text/vnd.wap.wml application/x-javascript application/rss+xml text/css application/javascript application/json;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

# How long to allow each connection to stay idle; longer values are better
# for each individual client, particularly for SSL, but means that worker
# connections are tied up longer. (Default: 65)
keepalive_timeout 65;

# Speed up file transfers by using sendfile() to copy directly
# between descriptors rather than using read()/write().
sendfile on;

# Tell Nginx not to send out partial frames; this increases throughput
# since TCP frames are filled up before being sent out. (adds TCP_CORK)
tcp_nopush on;


# Compression

# Enable Gzip compressed.
gzip on;

# Compression level (1-9).
# 5 is a perfect compromise between size and cpu usage, offering about
# 75% reduction for most ascii files (almost identical to level 9).
gzip_comp_level 5;

# Don't compress anything that's already small and unlikely to shrink much
# if at all (the default is 20 bytes, which is bad as that usually leads to
# larger files after gzipping).
gzip_min_length 256;

# Compress data even for clients that are connecting to us via proxies,
# identified by the "Via" header (required for CloudFront).
gzip_proxied any;

# Tell proxies to cache both the gzipped and regular version of a resource
# whenever the client's Accept-Encoding capabilities header varies;
# Avoids the issue where a non-gzip capable client (which is extremely rare
# today) would display gibberish if their proxy gave them the gzipped version.
gzip_vary on;

# Compress all output labeled with one of the following MIME-types.
gzip_types
application/atom+xml
application/javascript
application/json
application/rss+xml
application/vnd.ms-fontobject
application/x-font-ttf
application/x-web-app-manifest+json
application/xhtml+xml
application/xml
font/opentype
image/svg+xml
image/x-icon
text/css
text/plain
text/x-component;
# text/html is always compressed by HttpGzipModule

include /etc/nginx/conf.d/*.conf;
}
5 changes: 4 additions & 1 deletion bin/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,11 @@ setup_sudo() {
gpasswd -a $USERNAME systemd-journal
gpasswd -a $USERNAME systemd-network

# add go path to secure path
echo -e 'Defaults secure_path="/usr/local/go/bin:/home/jessie/.go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"' >> /etc/sudoers

# keep some enviornment variables
echo -e 'Defaults env_keep += "ftp_proxy http_proxy https_proxy no_proxy GOPATH EDITOR PATH"' >> /etc/sudoers
echo -e 'Defaults env_keep += "ftp_proxy http_proxy https_proxy no_proxy GOPATH EDITOR"' >> /etc/sudoers

# don't require a password
echo -e "${USERNAME} ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
Expand Down

0 comments on commit c32c7be

Please sign in to comment.