Railgun is an optimization technology from CloudFlare for accelerating dynamic web requests. To utilize Railgun, you must install the Railgun listener software on your origin server, and configure your Railgun on CloudFlare. This guide is for enabling Railgun on a CentOS 6 server with a LEMP stack.
- Nginx
- PHP
- PHP-FPM
- MySQL
openssl ecparam -out private.key -name prime256v1 -genkey
openssl req -new -key private.key -out csr.pem -config server.conf -reqexts req_ext
CSR server.conf file:
[req]
req_extensions = req_ext
distinguished_name = req_dn
default_md = sha256
[req_ext]
keyUsage = keyEncipherment, dataEncipherment
extendedKeyUsage = serverAuth
subjectAltName = @alt_names
[req_dn]
CN=issues4.us
[alt_names]
DNS.1 = example.com
DNS.2 = *.example.com
openssl req -x509 -sha256 -days 3650 -key private.key -in csr.pem -out server.pem
server {
listen 80;
listen [::]:80 ipv6only=on;
listen 443 ssl;
listen [::]:443 ssl ipv6only=on;
server_name example.com www.example.com;
ssl_session_timeout 5m;
ssl_session_cache shared:SSL:10m;
ssl_certificate /etc/nginx/certs/server.pem;
ssl_certificate_key /etc/nginx/certs/private.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_prefer_server_ciphers on;
}
yum install memcached
for i in `curl https://www.cloudflare.com/ips-v4`; do iptables -I INPUT -p tcp -s $i --dport 2408 -j ACCEPT; done
iptables-save | sudo tee /etc/sysconfig/iptables
for i in `curl https://www.cloudflare.com/ips-v6`; do ip6tables -I INPUT -p tcp -s $i --dport 2408 -j ACCEPT; done
ip6tables-save | sudo tee /etc/sysconfig/ip6tables
rpm -ivh http://pkg.cloudflare.com/cloudflare-release-latest.el6.rpm
rpm -Uvh railgun-el6.latest.rpm
Locate the Railgun activation key in your CloudFlare Account Railgun panel and modify these values in the /etc/railgun/railgun.conf
configuration file on the origin server:
activation.token = ACTIVATION_TOKEN
activation.railgun_host = ORIGIN_IP_ADDRESS
service railgun start
Prior to activating Railgun for the origin domain, test its connectivity and operation with the origin server.
curl -iv -o /dev/null -H "cf-setopt-wan-id: rg-WANIDHERE.port2408.net:2408" example.com -L
rg-diag -decode='d886bcd70a 0.31 0.041705 0030 5f99'
Compression ratio 0.31%
Railgun version 5f99
Railgun Flag rg-sender sent dictionary
Railgun Flag rg-listener found dictionary
curl -X GET "https://api.cloudflare.com/client/v4/zones/:zone_identifier/railguns/:identifier/diagnose" -H "X-Auth-Email: [email protected]" -H "X-Auth-Key: API_KEY" -H "Content-Type: application/json" | python -m json.tool
{
"errors": [],
"messages": [],
"result": {
"body_hash": "cf6d8b065bfe2d47f15072cf2ae9dc12dcc70645",
"body_size": "33319 bytes",
"cf-cache-status": "",
"cf-railgun": "6cfb707456 stream 0.000000 0210 5f99",
"cf-ray": "1f7b9a7e2aee11f5-SJC",
"cf-wan-error": "",
"cloudflare": "on",
"connection_close": "false",
"elapsed_time": "0.152064s",
"method": "GET",
"missing_headers": null,
"ord": "4 Silicon Valley (sv1)",
"protocol": "HTTP/1.1",
"railgun": "on",
"response_status": "200 OK",
"transfer_encoding": "chunked",
"url": "https://www.example.com"
},
"success": true
}
Enable redirection to HTTPS for all HTTP requests to the origin domain by adding a Page Rule to always use HTTPS for this pattern:
http://*example.com/*
Enable HSTS for the origin domain associated with the Railgun on the CloudFlare Crypto panel.
Important Note: Once HSTS is enabled for a domain, HTTPS service must always be enabled or the website will not load for visitors until it is re-enabled, or the HSTS policy expires.