Nginx 虚拟主机无法在 Ubuntu 24.04 上运行

问题描述 投票:0回答:1

我尝试在我的 Ubuntu 24.04 机器上的 Nginx 中设置虚拟主机,但它不起作用。我在可用站点中创建了一个配置文件并将其链接到已启用站点。但是,在尝试让我的虚拟主机 telbot.test 工作时,我遇到了权限问题和绑定错误。

我创建了以下虚拟主机配置:

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;
    }
}

我已采取的步骤:

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

重新启动 Nginx:我使用以下方法重新启动 Nginx:

bash sudo systemctl restart nginx

我期望 Nginx 加载 http://telbot.test,但它不起作用,并且在运行 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

此外,日志显示:

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

有人告诉我将虚拟主机放在 /etc/hosts 中,但我的 etc 目录中没有这个文件夹..

Ubuntu 24.04 Nginx 1.24.0

linux nginx virtualhost nginx-config ubuntu-24.04
1个回答
0
投票

据我所知 nginx 无法解析你的 import 语句。 为此,您必须将用户

www-data
添加到您要导入的用户组中。

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

但是将 www-data 用户添加到 sudo 用户 grp 中并不是一个好习惯。

因此,要么将

telbot.test
添加到
/etc/nginx/includes
,要么创建另一个没有任何 sudo 权限的用户。

© www.soinside.com 2019 - 2024. All rights reserved.