Skip to content

Instantly share code, notes, and snippets.

@Bharat-B
Created February 23, 2018 08:22
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save Bharat-B/62205bfd1dbe6d7ac9e24973c2bfd47e to your computer and use it in GitHub Desktop.
Save Bharat-B/62205bfd1dbe6d7ac9e24973c2bfd47e 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;
}
}
###
@eran101
Copy link

eran101 commented Nov 5, 2018

Thanks.
A semicolon is missing at the end of line 52.

@macroTbeast
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment