AKKAweb
AKKAweb

Reputation: 3807

NGINX Caching Symlinked Web Site Location

I have this weird issue that was not happening before.

I am running a Ubuntu Box on Digital Ocean that uses NGINX and PHP-FPM. I also use PHP Deployer to deploy code between Stage and Prod.

Deployer uses symlinks to tell the server where the files are in this case /var/www/mydommain.com/current would be the symlink that points to /var/www/mydomain.com/releases/26.

That is all good and if I do cd /var/www/mydomain.com/current it will change to releases/26. The website however is still pointing to releases/25. I have restarted NGINX and PHP-FPM multiple time without success.

Why is NGINX still pointing to releases/25 when the symlink actually points to releases/26? I can't get it.

In NGINX config for this domain I have root /var/www/mydomain.com/current

Upvotes: 2

Views: 605

Answers (2)

beingalex
beingalex

Reputation: 2476

This can be due to $document_root in your Nginx configuration being cached until you do sudo service php5.6-fpm restart.

You can replace $document_root with $realpath_root to avoid the caching.

This website helped me:

https://joshtronic.com/2019/07/29/symlinks-with-nginx-and-php-fpm/

Upvotes: 2

opznhaarlems
opznhaarlems

Reputation: 357

I know this is an 8 months old question, but this might help others:

I ran into the same issue and noticed that if I edit my index file (index.php) of the previous release, the symlink is magically refreshed.

After deploying, I simply run:

touch /path/to/releases/[previous_release_number]/public_html/index.php

...to update the file's modification timestamp.

I ended up including it in my deploy:symlink task like this:

task('deploy:symlink', function () {
    run("cd {{deploy_path}} && ln -sfn {{release_path}}/public_html ./public_html");
    run("touch {{previous_release}}/public_html/index.php");
})->desc('Linking latest version to public_html'); // <= Added this

Hope this helps. Regards, Wouter

Upvotes: 2

Related Questions