Skip to content

Instantly share code, notes, and snippets.

@EdHubbell
Last active December 24, 2015 01:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EdHubbell/6722317 to your computer and use it in GitHub Desktop.
Save EdHubbell/6722317 to your computer and use it in GitHub Desktop.
server {
listen [::]:80 default ipv6only=on; ## listen for ipv6
listen 80; ## listen for ipv4
server_name www.truxie.com truxie.com;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
# to restart, run
# service nginx restart
# that is all there is to it.
# to just reload the settings, you can use
# nginx -s reload
# serve static files
location ~ ^/(img|js|css|my|admin|landing|newsletter|report)/ {
root /srv/truxie/public;
expires 30d;
}
# cache.appcache andor offline.manifest
# this prevents any file with a .manifest or .appcache from being cached.
location ~* \.(?:manifest|appcache)$ {
proxy_pass http://127.0.0.1:3000;
expires -1;
}
# try out the socket connection.
location / {
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
# root /usr/share/nginx/html;
#}
}
# add servers for subdomains so we can host the subdomains on the same server.
server {
server_name admin.truxie.com;
rewrite ^/(.*?)/?$ http://www.truxie.com/admin/ redirect;
}
server {
server_name my.truxie.com;
rewrite ^/(.*?)/?$ http://www.truxie.com/my/ redirect;
}
#! /bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
### END INIT INFO
# after installing into /etc/init.d/, make sure to run these:
# sudo chmod +x /etc/init.d/nginx
# sudo /usr/sbin/update-rc.d -f nginx defaults
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/nginx/sbin/nginx
NAME=nginx
DESC=nginx
test -x $DAEMON || exit 0
# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
. /etc/default/nginx
fi
set -e
. /lib/lsb/init-functions
case "$1" in
start)
echo -n "Starting $DESC: "
start-stop-daemon --start --quiet --pidfile /usr/local/nginx/logs/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS || true
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
start-stop-daemon --stop --quiet --pidfile /usr/local/nginx/logs/$NAME.pid --exec $DAEMON || true
echo "$NAME."
;;
restart|force-reload)
echo -n "Restarting $DESC: "
start-stop-daemon --stop --quiet --pidfile /usr/local/nginx/logs/$NAME.pid --exec $DAEMON || true
sleep 1
start-stop-daemon --start --quiet --pidfile /usr/local/nginx/logs/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS || true
echo "$NAME."
;;
reload)
echo -n "Reloading $DESC configuration: "
start-stop-daemon --stop --signal HUP --quiet --pidfile /usr/local/nginx/logs/$NAME.pid --exec $DAEMON || true
echo "$NAME."
;;
status)
status_of_proc -p /usr/local/nginx/logs/$NAME.pid "$DAEMON" nginx exit 0 || exit $?
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|reload|force-reload|status}"
exit 1
;;
esac
exit 0
#!/bin/bash
#
# Deploy node.js, mongo DB and associated other requirements for Debain Wheezy server
# create this script in /usr/local/sbin/ and then run chmod 755 /usr/local/sbin/nodeServerSetup.sh
# then run the script
# --------------------------------------------------------------------------
#
apt-get update
apt-get upgrade
# install ntp server - twitter api is really picky about timestamp of incoming requests.
# add all kinds of other prereqs to installing node or nginx
apt-get install ntp ntpdate build-essential curl git-core openssl libssl-dev
# nginx prereqs
apt-get install libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlib1g-dev
# lets get monit on here as well...
apt-get install monit
# tell monit that it should look for monit config files in the /etc/monit.d/* folder
echo 'include /etc/monit.d/*' >> /etc/monit/monitrc
mkdir /usr/local/sbin/nginxsource
cd /usr/local/sbin/nginxsource
wget http://nginx.org/download/nginx-1.4.1.tar.gz
tar -zxvf nginx-1.4.1.tar.gz
cd /usr/local/sbin/nginxsource/nginx-1.4.1/
# added --with-ipv6
./configure --with-http_ssl_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--without-mail_pop3_module \
--without-mail_imap_module \
--without-mail_smtp_module \
--with-ipv6
#./configure --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-ipv6
#./configure --prefix=/usr --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx.lock --with-http_ssl_module --user=www-data --group=www-data --with-http_stub_status_module --with-http_gzip_static_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-ipv6
make
sudo make install
cd /usr/local/sbin/
# install nginx and hell, start it. probably need to configure it as well, but you can do that later.
#apt-get install nginx
#/etc/init.d/nginx start
git clone https://github.com/joyent/node.git
cd node
# 'git tag' shows all available versions: select the latest stable.
git checkout v0.10.18
# Configure seems not to find libssl by default so we give it an explicit pointer.
# Optionally: you can isolate node by adding --prefix=/opt/node
./configure --openssl-libpath=/usr/lib/ssl
make
# wtf is this for? I dunno.
make test
sudo make install
node -v # it's alive!
# Luck us: NPM is packaged with Node.js source so this is now installed too
npm -v # it's alive!
# install coffee script globally
npm -g install coffee-script
# we use the new pm2 instead of forever.js
npm install -g pm2
# install mongodb
apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
echo 'deb http://downloads-distro.mongodb.org/repo/debian-sysvinit dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
apt-get update
apt-get install mongodb-10gen
# what now? Add init.d script and config files for nginx
# you want to run a node socket IO demo?
# check out this: https://github.com/mmukhin/psitsmike_example_1
@EdHubbell
Copy link
Author

These 3 scripts should get you well on your way to making your own debian server build with MongoDB and node with nginx and socket.io support. All on one box. Works well with rackspace. From zero to socket.io capable instance in about a half hour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment