I followed this tutorial. How To Set Up Nginx Server Blocks (Virtual Hosts) on Ubuntu 14.04 LTS
I have an Ubuntu 16.04 server with Nginx. I have had a production website running under Default for almost a year. It is located at /var/www/html. I used the tutorial to add another Server Block to point to /var/www/causeaction.com/html. I created the new server block in the file /etc/nginx/sites-available/causeaction.com. I linked that file to /etc/nginx/sites-enabled.
I edited the line in nginx.conf as stated in the tutorial.
When I tried to restart Nginx it failed. My production site is now down! So I deleted the link and the new server block file and was able to start Nginx again. Whew!
The new server block file, causeaction.com, contained ONLY what was mentioned in the Example as below:
server { listen 80 default_server; listen [::]:80 default_server ipv6only=on;
root /var/www/causeaction.com/html;
index.php index index.html index.htm;
server_name causeaction.com www.causeaction.com;
location / {
try_files $uri $uri/ =404;
}
}
I then noticed that the original Default server block was Much larger and contained a bunch more lines. Must I include in the new server block file ALL the lines that were in the original Default file but just change the entries at the top??? Note I kept the old Default file because it referred to the production website which is VERY important to keep running.
Thanks for any help.
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!
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.
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
nginx -t
is a helpful command to check your configs before a restart/reloadWell I guess that was the answer. I noticed while looking at the default server block that the php location block was indeed inside the server block of code. I copied the rest of the default server block code in to my new server block and php is now working. A very important point to add to the Digital Ocean tutorial I used to create my new server block.
I had thought that anything in the default server block would be applied to ALL server blocks. Not so!
When nginx failed to start it likely included some details on the error it encountered. If they were not then you should be able to find these details in /var/log/nginx/error.log.
By default the config files in /etc/nginx/sites-enabled (and sites-available) should end in .conf - I do not know if this will cause a failure like the one you experienced but it is best practice for nginx configuration files.