So, I'm setting up a backend api on Amazon Linux 2 and I have installed Nginx, set up a service systemd file that uses Gunicorn to run the django instance and create a sock file at /home/ec2-user/backend/testsite.sock.
That file is getting created properly. Loading that file into the Nginx /etc/nginx/conf.d/testsite.com server block.
The Issue: The server is showing the Welcome to Amazon Linux 2 page even though both the systemd file and nginx config are both showing as running and there are no errors.
testsite.com Nginx file:
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;
}
}
I've set up the security group to allow HTTP on port 80 and when I visit http://api.testsite.com, I'm seeing this page still:
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 status output:
(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.
So, I'm not getting any errors. To test the Django installation, I've enabled port 8000 on AWS Security Groups and when I manually run:
python manage.py runserver 0.0.0.0:8000
I'm able to access it via api.testsite.com:8000 and log in etc. But when I try to go to api.testsite.com it still shows the AmazonLinux2 welcome page. I don't understand why Nginx isn't taking over and serving the Django instance. Weird thing is this, when I go to http://api.testsite.com/admin I'm getting an nginx error page.
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.
I'm thinking surely this is something simple that I must be overlooking and I thank anyone for any help! I'm just at my wits end ha ha. Thank you again!
Edit The Nginx error log is showing no errors
I am using Django Storages for my static and media files so I didn't think I needed to include them in the Nginx server block.
The contents of proxy_params that I'm including in my testsite.com Nginx file:
proxy_set_header Host \$http_host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;