Let’s Encrypt overwrites customized nginx SSL conf

There is Vesta CP and WordPress installed. In order to have nice looking URLs we have to add

try_files $uri $uri/ /index.php?$args;

line under “location /” block of nginx conf file. It works just fine. But if you’ll enable Let’s Encrypt SSL support and then add this rule to SSL enabled config, you’ll have 404 HTTP error on your nice looking URLs every 3 months. The thing is that Let’s Encrypt overwrites nginx SSL conf file on every certificate renewal. So one of the solutions is to look for include directive in that nginx SSL conf file. In particular case we have

include /home/username/conf/web/snginx.domainname.com.conf*;

directive at the end of nginx SSL conf file. So we need to create that file: snginx.domainname.com.conf-custom for example. And add there:

location ~* {
try_files $uri $uri/ /index.php?$args;

We have to use “location ~*” instead of “location /” because nginx does NOT allow duplicate instances of “location /” and we get error like:
nginx: [emerg] duplicate location “/” in /home/username/conf/web/snginx.domainname.com.conf-custom:1

This is what this article is all about. It’s not easy to google this exact information, even it’s crutial for nginx/Wordpress/SSL installation.


P.S. Перепрошую за англійську, писав на швидку руку і не зауважив що пишу англійскою на україномовний ресурс.

Напишіть відгук

Ваша пошт@ не публікуватиметься. Обов’язкові поля позначені *

* Copy This Password *

* Type Or Paste Password Here *

Можна використовувати XHTML теґи та атрибути: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>