Update nginx without loosing configuration

September 27, 2016 7.5k views
Nginx Ubuntu

i need to update my nginx to latest stable version. how can i do that without loosing my server blocks and nginx.conf file. i mean how can i backup all configuration before updating nginx and restore them back.

thanks in advance.

1 Answer
kamaln7 MOD September 28, 2016
Accepted Answer


Updating nginx should not affect any config files that you have created or modified. You can update nginx to the latest version by running sudo apt-get update to update the package lists, followed by sudo apt-get install nginx.

If you want to be extra careful, you can back up the /etc/nginx directory which contains all of nginx’s config files.

sudo cp -r /etc/nginx /etc/nginx.pre-upgrade

After upgrading the package, you can delete /etc/nginx and move /etc/nginx.pre-upgrade back to /etc/nginx. However, as I said, it is unnecessary and completely optional to do it.

Have another answer? Share your knowledge.