Question

Update nginx without loosing configuration

Hello, 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.


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
September 28, 2016
Accepted Answer

Hi!

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.

I just observed that a recent Nginx upgrade did the following:

  1. It clobbered my personalized /usr/share/nginx/html/index.html file, replacing it with the default Nginx welcome page
  2. It restored the /etc/nginx/conf.d/default.conf site config.

The first bullet can be addressed… from my personalized site config I can serve my static files up from a different direction.

But I don’t know how to address the 2nd bullet. Upgrading Nginx essentially takes down your website and replaces it with a welcome page.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.