In maybe an ill-advised attempt to boost usage of Swift on the web, I set out to build my personal website using Swift.
The Vapor server hosts the root document, along with a WebSocket server for a web Swift Playground environment.
git clone firstname.lastname@example.org:hallee/hal.codes.git cd hal.codes/ ./run.sh vapor xcode yarn npx webpack -d --watch
eval "$(curl -sL https://apt.vapor.sh)" sudo apt-get install swift vapor cd ~ git clone email@example.com:hallee/hal.codes.git cd hal.codes/ ./run.sh vapor build --release nano hal-codes.service # change the working directory to match your system sudo cp hal-codes.service /lib/systemd/system/ sudo systemctl enable hal-codes.service
At this point the Vapor server will be running on port
8080. The systemd service ensures that the server stays up continuously, even after reboots.
To route public traffic on port
443 to the Vapor server, I use Nginx with a proxy configuration.
Since css and js files are already gzipped by webpack, Nginx's
gzip_static module is required to serve them without the server recompresisng them, which unforutnately requires building Nginx from source.
sudo apt-get install nginx-common nginx-core sudo apt-get build-dep nginx cd /tmp/ sudo apt-get source nginx cd nginx-1.10.3/ # version number may differ sudo nano auto/options # change HTTP_GZIP_STATIC=NO to YES sudo dpkg-buildpackage -uc -b sudo dpkg -i ../nginx_1.10.3-0ubuntu0.16.04.2_all.deb # package name may differ
Now that Nginx is built with proper gzip support, we can set it up:
cd ~/hal.codes/ sudo cp nginx.conf /etc/nginx/sites-available/hal.codes sudo ln -s /etc/nginx/sites-available/hal.codes /etc/nginx/sites-enabled/ sudo rm /etc/nginx/sites-enabled/default sudo systemctl enable nginx
To setup HTTPS, I used Let's Encrypt's Certbot.