Nginx 安装显示 AmazonLinux2 欢迎页面

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

所以,我在 Amazon Linux 2 上设置了一个后端 api,我已经安装了 Nginx,设置了一个使用 Gunicorn 运行 django 实例的服务 systemd 文件,并在 /home/ec2-user/backend/ 创建了一个 sock 文件测试站点.sock.

该文件正在正确创建。将该文件加载到 Nginx /etc/nginx/conf.d/testsite.com 服务器块中。

问题: 服务器显示欢迎使用 Amazon Linux 2 页面,即使 systemd 文件和 nginx 配置都显示为正在运行并且没有错误。

testsite.com Nginx 文件:

server {
    server_name api.testsite.com;
    listen 80;
    location = /favicon.ico { access_log off; log_not_found off; }
    location / {
    include proxy_params;
    error_log logs/error.log warn;
    proxy_pass http://unix:/home/ec2-user/backend/testsite.sock;
    }
}

我已经设置了安全组以允许端口 80 上的 HTTP,当我访问 http://api.testsite.com 时,我仍然看到这个页面:

Thank you for using Amazon Linux 2.

Now that you have it installed, find announcements and discussion in the AWS Discussion Forums. Also try AWS documentation.

Nginx 状态输出:

(venv) [ec2-user@testsite conf.d]$ sudo systemctl status nginx.service
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since Sun 2023-04-02 05:33:49 UTC; 39min ago
Process: 3395 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
Process: 3391 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
Process: 3389 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
Main PID: 3397 (nginx)
CGroup: /system.slice/nginx.service
├─3397 nginx: master process /usr/sbin/nginx
└─3398 nginx: worker process

Apr 02 05:33:49 testsite.com systemd[1]: Stopped The nginx HTTP and reverse proxy server.
Apr 02 05:33:49 testsite.com systemd[1]: Starting The nginx HTTP and reverse proxy server...
Apr 02 05:33:49 testsite.com nginx[3391]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Apr 02 05:33:49 testsite.com nginx[3391]: nginx: configuration file /etc/nginx/nginx.conf test is su...sful
Apr 02 05:33:49 testsite.com systemd[1]: Started The nginx HTTP and reverse proxy server.
Hint: Some lines were ellipsized, use -l to show in full.

所以,我没有收到任何错误。为了测试 Django 安装,我在 AWS 安全组上启用了端口 8000,当我手动运行时:

python manage.py runserver 0.0.0.0:8000

我可以通过 api.testsite.com:8000 访问它并登录等。但是当我尝试去 api.testsite.com 它仍然显示 AmazonLinux2 欢迎页面。我不明白为什么 Nginx 没有接管并为 Django 实例提供服务。奇怪的是,当我去 http://api.testsite.com/admin 我得到一个 nginx 错误页面。

The page you are looking for is not found.
Website Administrator
Something has triggered missing webpage on your website. This is the default 404 error page for nginx that is distributed with Fedora. It is located /usr/share/nginx/html/404.html

You should customize this error page for your own site or edit the error_page directive in the nginx configuration file /etc/nginx/nginx.conf.

我在想这肯定是我必须忽略的简单事情,我感谢任何人的帮助!我只是无计可施哈哈。再次感谢!

django amazon-web-services nginx gunicorn amazon-linux-2
© www.soinside.com 2019 - 2024. All rights reserved.