Skip to content

Instantly share code, notes, and snippets.

@Bharat-B
Last active March 4, 2024 18:02
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save Bharat-B/6ba2e18f85591c77fdf00ad7334fb9c6 to your computer and use it in GitHub Desktop.
Save Bharat-B/6ba2e18f85591c77fdf00ad7334fb9c6 to your computer and use it in GitHub Desktop.
nGINX rewrite rules for whmcs 8
server {
listen 80 default_server;
server_name readydedis.com www.readydedis.com;
return 301 https://readydedis.com$request_uri;
}
# HTTPS server
#
server {
listen 443;
server_name readydedis.com;
root /var/www/html/public;
access_log /var/log/nginx/readydedis.com-access_log;
error_log /var/log/nginx/readydedis.com-error_log;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
index index.php index.html index.htm;
charset utf-8;
ssl on;
ssl_certificate /var/www/html/storage/ssl/cert.pem;
ssl_certificate_key /var/www/html/storage/ssl/cert.key;
ssl_session_timeout 5m;
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES";
ssl_prefer_server_ciphers on;
location ~ /clients/admin/(client!\.php|client/(.*)|table/(.*)|search!\.php|search/(.*)|apps|billing|setup|user|services|addons|domains|utilitiesemailmarketer!\.php|utilities/(.*)|logs|help!\.php|help/license|modules|image/(recent|upload)|validation_com/(.*))/?(.*)$ {
rewrite ^/(.*)$ /clients/admin/index.php?rp=/admin/$1/$2;
}
location ~ /clients/(images/em|invoice|login|password|account|store|download|knowledgebase|announcements|clientarea/ssl-certificates|user/(verification|accounts|profile|password|security|verify)|cart/(domain/renew)|domain/pricing|cart/order|images/kb)/?(.*)$ {
rewrite ^/(.*)$ /clients/index.php?rp=/$1/$2;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
location ^~ /clients/vendor/ {
deny all;
return 403;
}
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc|svg|woff|woff2|ttf)\$ {
expires 1M;
access_log off;
add_header Cache-Control "public";
}
location ~* \.(?:css|js)\$ {
expires 7d;
access_log off;
add_header Cache-Control "public";
}
location ~ /\.ht {
deny all;
}
}
@Masu-Baumgartner
Copy link

Thanks. This is exactly what i needed to make my whmcs instance working :)

@stefanofabi
Copy link

Thanks!

@jorgefduran
Copy link

Hi, apparently the "Login as Owner" function will not work with NGINX. Have you found a solution for that?

@Masu-Baumgartner
Copy link

I'm using NGINX too and its working fine ^^

@jorgefduran
Copy link

Hi Marcel, from my whmcs installation I can't use the "Login as Owner" function, the URL stays at:

https://domainname.com/whmcs/admin/client/1/login

Where 1 = clientID

And I can't get in.
I have checked all the configuration lines more than once and they are exactly the same as the ones I have in nginx, could you share your configuration please?

@Masu-Baumgartner
Copy link

Hi jorgefduran,

Maybe the issue is the /whmcs/. I certainly wouldn't be surprised because WHMCS is just weird. I'm currently not at home so i'm not able login in my aaPanel to copy my configuration because of me not remember my 32 char password ^^

@jorgefduran
Copy link

I understand, if it were possible to do it when you are at your home I would greatly appreciate it.

@Bharat-B
Copy link
Author

@jorgefduran for it to work for you you should replace /clients/ in the nginx config on line 36 and 40 with /whmcs/

@jorgefduran
Copy link

@Bharat-B, yes I have replaced, with my own path.

@jorgefduran
Copy link

Sorry... was my mistake... my custom admin directory was missing in the config. Thank you @Bharat-B and @Marcel-Baumgartner

@Masu-Baumgartner
Copy link

No problem ^^

@kapatheus
Copy link

Any idea why the login doesn't work with this conf? login.php shows 404 and admin login page .css not loading. When I remove this section, they work.
location ~ /(images/em|invoice|login|password|account|store|download|knowledgebase|announcements|clientarea/ssl-certificates|user/(verification|accounts|profile|password|security|verify)|cart/(domain/renew)|domain/pricing|cart/order|images/kb)/?(.*)$ { rewrite ^/(.*)$ /index.php?rp=/$1/$2; }

I have WHMCS installed in the root, that's why I have removed the clients path from here.

@edbrk
Copy link

edbrk commented Jul 18, 2023

Also having the same issue that Login isnt working.

@notmods
Copy link

notmods commented Dec 31, 2023

Same issue as the two commenters above on a new install. Interestingly, it's working fine on another installation I have.

@tradenet
Copy link

tradenet commented Mar 3, 2024

Having issues with domainchecker.php returning a 404 error. I've even disabled friendly URLS and still get that issue. Anyone have any ideas?

@Bharat-B
Copy link
Author

Bharat-B commented Mar 4, 2024

Having issues with domainchecker.php returning a 404 error. I've even disabled friendly URLS and still get that issue. Anyone have any ideas?

Every version has newer links and routes, this specific nginx config is for an older one, please reach out to me on +91 8686927397 I'll help :)

@Bharat-B
Copy link
Author

Bharat-B commented Mar 4, 2024

//For Admin area

location ~ /clients/admin/(client!\.php|client/(.*)|table/(.*)|search!\.php|search/(.*)|apps|billing|setup|user|services|addons|account/(.*)|domains|utilitiesemailmarketer!\.php|utilities/(.*)|logs|help!\.php|help/license|modules|image/(recent|upload)|validation_com/(.*))/?(.*)$ {
			rewrite ^/(.*)$ /clients/admin/index.php?rp=/admin/$1/$2;



//For clientarea

	location ~ /clients/(invite|images/em|invoice|login|password|account|store|download|knowledgebase|announcements|clientarea/ssl-certificates|user/(verification|accounts|profile|password|security|verify)|cart/(domain/renew)|domain/pricing|cart/order|images/kb)/?(.*)$ {
                rewrite ^/(.*)$ /clients/index.php?rp=/$1/$2;
	}



@tradenet
Copy link

tradenet commented Mar 4, 2024

//For Admin area

location ~ /clients/admin/(client!\.php|client/(.*)|table/(.*)|search!\.php|search/(.*)|apps|billing|setup|user|services|addons|account/(.*)|domains|utilitiesemailmarketer!\.php|utilities/(.*)|logs|help!\.php|help/license|modules|image/(recent|upload)|validation_com/(.*))/?(.*)$ {
			rewrite ^/(.*)$ /clients/admin/index.php?rp=/admin/$1/$2;



//For clientarea

	location ~ /clients/(invite|images/em|invoice|login|password|account|store|download|knowledgebase|announcements|clientarea/ssl-certificates|user/(verification|accounts|profile|password|security|verify)|cart/(domain/renew)|domain/pricing|cart/order|images/kb)/?(.*)$ {
                rewrite ^/(.*)$ /clients/index.php?rp=/$1/$2;
	}

Fantastic! Thank you, this works with WHMCS v8.8

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