-
-
Notifications
You must be signed in to change notification settings - Fork 70
Server setup
Next, it is up to you to choose how to actually serve the site. Most people run rails' webserver behind Apache or NGINX where Apache/NGINX performs a reverse proxy. For this tutorial we will assume you are using NGINX, but a similar configuration should be required for Apache. You can find numerous tutorials online by searching for "rails puma with nginx" or "rails puma with apache" (Puma is the name of the webserver used by default by QPixel).
You need to make sure that rails runs as a service. You probably also want to make sure the service starts with your server.
If you are using systemd (Ubuntu), you can create a file at /etc/systemd/system/qpixel.service
:
[Unit]
Description=QPixel
After=network.target
After=mysql.service
Requires=mysql.service
[Service]
User=<user running the service>
Group=<group running the service>
WorkingDirectory=<location for qpixel server files, e.g. /var/www/qpixel>
ExecStart=bundle exec rails s -e production
TimeoutStartSec=3600
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
Next, reload, enable, and start the service:
sudo systemctl daemon-reload
sudo systemctl enable qpixel
sudo systemctl start qpixel
By default, codidact uses NGINX to serve the assets from the public
folder. It is also possible to have puma serve these files. If you want to do so, we recommend that you set a cache header on them to ensure that your server is not flooded with requests for simple assets. In config/environments/production.rb
, you set the following to serve them and have these files be cached:
config.public_file_server.enabled = true
config.public_file_server.headers = {
'Cache-Control' => "public, max-age=#{5.days.to_i}"
}
You can alter the max age from 5 to a different number of days if you so desire.
You need to set NGINX to a reverse proxy. Additionally, you need to set the HOST header such that rails knows what site the request came from. Create a normal NGINX configuration and add the following for the reverse proxy:
proxy_pass http://localhost:3000;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
If you bind rails to a different address or port, you need to configure that here.
Assuming that your service is started (systemctl start qpixel
) and your nginx configured, you should now be able to visit your site in your browser!