Set up Directus in Nginx
This article assumes you have installed both Directus and Nginx and are wanting to access Directus via a hostname rather than IP:Port.
Create a new Nginx config file:
vim /etc/nginx/conf.d/directus.example.com.conf
Copy and Paste the following template and replace the server_name and proxy_pass port with your details. You will also need to supply your SSL configuration. If you don't need SSL, remove the listening port 443 line.
server {
listen 80;
listen 443 ssl http2;
server_name directus.example.com;
# Include your SSL details here #
location / {
proxy_pass http://127.0.0.1:8055;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
add_header X-Cache $upstream_cache_status;
proxy_connect_timeout 30s;
proxy_read_timeout 86400s;
proxy_send_timeout 30s;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
access_log /var/log/nginx/directus.example.com.log;
error_log /var/log/nginx/directus.example.com.error.log;
}
Save and close your configuration file. If you are unfamilar with vim, make sure to exit the editor mode by pressing ESC, the type :wq and press ENTER.
Test your nginx configuration using:
nginx -t
If unsuccessful, the output will say where the error occured. Address the issue and repeat.
Restart Nginx to apply the changes.
service nginx restart
You can now access Directus from your domain name (assuming the DNS is configured and port 80 and 443 are open on the firewall).
403 Gateway Issue
Are you getting the 403 Gateway issue? This means your nginx configuration is trying to load the proxy address 127.0.0.1:8055 and there is nothing running. Make sure your Directus project has been started, the port is correct or the service is running.