Skip to content

Instantly share code, notes, and snippets.

@mhrubel
Forked from Bharat-B/hostname.conf
Created February 8, 2019 13:43
Show Gist options
  • Save mhrubel/cde0b879f3021207e2ad1d4aa176107c to your computer and use it in GitHub Desktop.
Save mhrubel/cde0b879f3021207e2ad1d4aa176107c to your computer and use it in GitHub Desktop.
WHMCS nGINX rules for SSL / Non SSL
### NON SSL | STANDARD HTTP
server {
listen 80;
server_name domain.com;
root /path/to/whmcs;
index index.php index.html;
access_log /var/log/nginx/domain.com.log combined;
access_log /var/log/nginx/domain.com.bytes bytes;
error_log /var/log/nginx/domain.com.error.log error;
location / {
try_files $uri $uri/ /index.php?$query_string;
location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ {
expires max;
}
location ~ [^/]\.php(/|$) {
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_pass unix:/path/to/php-fpm.sock;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
}
}
location ~ /announcements/?(.*)$ {
rewrite ^/(.*)$ /index.php?rp=/announcements/$1;
}
location ~ /downloads/?(.*)$ {
rewrite ^/(.*)$ /index.php?rp=/downloads/$1;
}
location ~ /knowledgebase/?(.*)$ {
rewrite ^/(.*)$ /index.php?rp=/knowledgebase/$1;
}
error_page 403 /error/404.html;
error_page 404 /error/404.html;
error_page 500 502 503 504 /error/50x.html;
location ~* "/\.(htaccess|htpasswd)$" {
deny all;
return 404;
}
}
###
### SSL | SECURE HTTPS
server {
listen 443;
server_name domain.com;
root /path/to/whmcs;
index index.php index.html;
access_log /var/log/nginx/domain.com.log combined;
access_log /var/log/nginx/domain.com.bytes bytes;
error_log /var/log/nginx/domain.com.error.log error;
ssl on;
ssl_certificate /path/to/ssl.pem;
ssl_certificate_key /path/to/ssl.key;
location / {
try_files $uri $uri/ /index.php?$query_string;
location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ {
expires max;
}
location ~ [^/]\.php(/|$) {
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_pass unix:/path/to/php-fpm.sock;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
fastcgi_read_timeout 30;
}
}
location ~ /announcements/?(.*)$ {
rewrite ^/(.*)$ /index.php?rp=/announcements/$1;
}
location ~ /downloads/?(.*)$ {
rewrite ^/(.*)$ /index.php?rp=/downloads/$1;
}
location ~ /knowledgebase/?(.*)$ {
rewrite ^/(.*)$ /index.php?rp=/knowledgebase/$1;
}
error_page 403 /error/404.html;
error_page 404 /error/404.html;
error_page 500 502 503 504 /error/50x.html;
location ~* "/\.(htaccess|htpasswd)$" {
deny all;
return 404;
}
}
###
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment