skip to Main Content

I’m trying to set up a virtual host in Nginx on my Ubuntu 24.04 machine, but it’s not working. I’ve created a configuration file in sites-available and linked it to sites-enabled. However, I’m encountering permission issues and binding errors when trying to get my virtual host telbot.test to work.

I created the following virtual host configuration:

server {
    listen 80;
    listen [::]:80;

    server_name telbot.test;

    root /home/amyr/Desktop/Nginx/telbot.test;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}

Steps I have taken:

Symlink Created: I created a symlink from sites-available to sites-enabled.
Firewall Checked: UFW is active and allows Nginx traffic.
Hosts File Updated: Added 127.0.0.1 telbot.test to /etc/hosts.
Permissions Set: I set ownership of the directory to www-data using:

bash sudo chown -R www-data:www-data /home/amyr/Desktop/Nginx/telbot.test

Restarted Nginx: I restarted Nginx using:

bash sudo systemctl restart nginx

I expected Nginx to load http://telbot.test, but it doesn’t work, and I receive the following errors when running nginx -t:

2024/09/24 13:10:26 [warn] 183991#183991: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
2024/09/24 13:10:26 [emerg] 183991#183991: open() "/run/nginx.pid" failed (13: Permission denied)
nginx: configuration file /etc/nginx/nginx.conf test failed

Additionally, the logs show:

[crit] 89335#89335: *3 stat() "/home/amyr/Desktop/Nginx/" failed (13: Permission denied)
[emerg] 183991#183991: open() "/run/nginx.pid" failed (13: Permission denied)

Someone told me to put my virtual host in my /etc/hosts but I don’t have this folder in my etc directory..

Ubuntu 24.04
Nginx 1.24.0

2

Answers


  1. Chosen as BEST ANSWER

    It was just because of "etc/hosts" file (I forgot to add my new virtual hosts).

    Thanks for the answers 💙


  2. AFAIK nginx cant parse your import statement.
    To achieve it, you have to add the user www-data to your users grp, where you want to import.

    sudo usermod -aG {{GRP_NAME}} www-data

    But adding the www-data user to your sudo users grp is a very bad practice.

    So either you add your telbot.test to your /etc/nginx/includes or you create another user without any sudo permissions.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search