Getting errors while installing nginx

While installing nginx, I am getting some few errors, these are the errors
-"/var/log/nginx/error.log" failed (13: Permission denied)

  • “etc/nginx/sites/-enabled/letsecrypt” failed (21: is a directory)

  • configuration file /etc/nginx/nginx.conf test failed

curl http://localhost
curl (7) Failed to connect to localhost port 80:Connection refused.

systemctl status nginx
Active: failed

Please help. Really need help.
Thanks

Hello @pooh_bear, I’m sorry to hear you’re having issues, with a bit of additional information I believe I can help you fix this.

So that I can better understand what the issue may be, would you be willing to provide the following?

  • OS version & architecture
  • Nginx configuration file contents
  • output of running the command (If on Linux) ls -alh /var/log/
  • Further details about any firewall that you may have running, and if running, what the rules are for the firewall (Ex. block all requests on port 21, allow all requests on 80, etc.)

Thanks!

Thank you so much!!!

I am working on windows 10.

To install NGINX on Ubuntu Server:
curl http://localhost
“/etc/nginx/sites-enabled/letsencrypt” failed

I don’t get any output on ls -alh/var/log/

ERR connection refused.

I’m somewhat confused honestly. It seems to me that you are working with software that is meant for linux operating systems only, on a windows 10 environment. Is this correct?

Yes, I am working on windows. Btw, ls -alh /var/log/ on this I am getting some lists.

Ahh yes, the alh flag will list all files, in a list, in human-readable format, including hidden files. What are the files that you are getting as output? These should be the error and runtime log files, which will be very helpful to see the contents of, to further diagnose the issues your having and get it resolved.

On “postgresql” is kinda dark highlight…Could this be an error???

What specifically is highlighted? Is it files of different types highlighted with different colors?
It might be helpful if you could maybe provide a screenshot of what you see on your end to help us understand a bit better :slight_smile:

Thank you so much! That makes things so much clearer! So, just for clarification for your sake, the red-colored files are .gz files, which are essentially the Linux version of a .zip file; they each have multiple older log files in them. In the /var/log/nginx/ folder, you should have the logs from the server, and specifically, one of them should be called error.log or something along those lines, can you copy and paste the contents of that file here? That will show us exactly what the server itself is saying is wrong with itself, and give us information on what needs to be fixed.

well, the contents of the log, yes. If you run the command cat /var/log/nginx/error.log and paste that output here, that will provide information, a lot of very useful information.

Ok. This is what I got.

Well crap. I guess you must not even have been able to get far enough in the startup process to generate an error log, or because of the permissions issues referenced in the original post that started this thread. That sucks :laughing: Don’t worry though, we’ll get this figured out!

Based on your original post, I think that there are a few things that need to be checked.

Could you run the command ufw allow 80 and ufw allow http to make sure that your firewall is allowing port 80 (the default HTTP protocol port) to transmit data.

This leads me to think that there may have been an error made in the configuration of the Nginx server configuration file. I’d like to personally take a look, if your willing to share the contents of the file with me. You can retrieve the contents by using the following command: cat /etc/nginx/nginx.conf and copy/pasting the resulting output here.

I’d like to check the permissions of the directories leading up to the /var/log/nginx/error.log file, and then the permissions of the error.log file itself. We can do this by running the following commands:

  • Check the permissions of the folder /var/ with the command ls -alh /
    (we need to see the folder var’s own permissions, which is why we have to start a folder back, as we will need to do for each of the following. Don’t worry about going a folder back, the commands I’m providing here take care of that for you :slight_smile:
  • Check the permissions of the folder /var/log/ with the command ls -alh /var/ this will show us the contents of the folder /var/ including the folder /log/.
  • Check the permissions of the folder /var/log/nginx/ with the command ls -alh /var/log/
    This will allow us to see the folder nginx’s permissions in the file system.
  • Finally, the error logs themselves, which can be done with the command ls -alh /var/log/nginx/.

As a reference, I have included a screenshot of my own web server in which I ran the command ls -alh /var/log/nginx/ to provide a sample of what the expected output should look like, seen below.

image

As a bit of an explanation of the output information that you will be getting with the command ls -alh [filepath], I wanted to include the following. If your not interested or you already know this, by all means feel no obligation to read any further, If nothing else it’ll be a reference for other forum users.

Let us use the example from the screenshot I provided, the line
-rw-r----- 1 www-data adm 0 Sep 15 02:25 access.log

This section containing -rw-r----- is telling us the actual permissions of the file itself, where r stands for read permissions, w stands for write permissions, and (although this file doesn’t have this permission, so you cannot see it) e stands for execution permissions, or in other words, permission to run the program.

The number 1 following the previous represents the number of objects contained within the file, which, because there are no folders located within the text file, is 1, for itself.

Following the 1 is www-data adm which tells the human the file’s owner and group assignment within the system. This is very important. If the group and file owner is incorrectly set, this can restrict certain crucial system functions from being able to access or open the file, potentially resulting in the error permission denied message such as the one found in your initial post.

Following the system group and owner is the file size, converted from plain bytes into a human-readable format with the flag -h in the command ls. Because I use the Apache webserver for my Mattermost instance, and do not run Nginx except as a backup, my error.log file has a size of 0, meaning that it is an empty file.

Finally, after the file size, you have the date and time that the file was last modified, and then the name of the file itself!

I think I finally understand what may be causing a big issue. I’m guessing that there is a folder called letsencrypt if you were to change directories to /egc/nginx/sites-enabled/ and run the command ls? If yes, this is the first issue that needs to be remediated, as only individual website configuration files ending in .conf should be in the folder /etc/nginx/sites-enabled/, and no other folders should be in it. Because Nginx parses all files in the /etc/nginx/sites-enabled/ folder to load each website’s configuration file when it starts, and there is a directory in this folder, this would be (at least one) of the reasons that your server isn’t starting.

Can I ask why the letsencrypt folder is located in the /etc/nginx/sites-enabled/ folder?

As a follow up, to move the letsencrypt folder to the proper location, use the mv command to move the folder to the correct location. You can do this with this command:
mv /etc/nginx/sites-enabled/letsencrypt/ /etc/letsencrypt/
This command will move the folder to the location /etc/letsencrypt which is the standard location.

Once you have done this, I suggest taking a look at the example Nginx configuration file for Mattermost, which you can find at https://docs.mattermost.com/install/config-proxy-nginx.html, and get setup with a few small changes to the template provided on the documentation website, linked above.

To see if it has worked, after doing the above, run the command sudo systemctl restart nginx and if it doesn’t work, please provide the output of sudo systemctl status nginx so we can additionally troubleshoot!

I Don’t know how that happen, Can you help how to solve that???

Thanks

Yes I can! So, what the mv command is, is a Linux command utility to move a file or folder to another location.

The required arguments are as follows:
mv /path/to/file/or/folder/ /location/to/move/foler/to

In your command, you only had mv /path/to/file/or/folder/
To fix this, simply add /etc/letsencrypt/ to the command, to form a complete command like this:
mv /etc/nginx/sites-enabled/letsencrypt/ /etc/letsencrypt/

I hope that helps you!

1 Like

My apologies, I use my linux servers as the root user so I forget that non-root users have to use sudo, it should work as
sudo mv /etc/nginx/sites-enabled/letsencrypt/ /etc/letsencrypt/

1 Like

Oh my god!! It worked, :slight_smile:

Thank you so much!!!

1 Like

That’s great, I’m so excited to hear that!! :grinning: Is everything functioning as expected now?

Yes. It is working perfectly fine.
Thanks.

1 Like