You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

已配置IPv4访问Django索引页,如何为域名配置Nginx对应设置?

Fixing Nginx Default Page for Your Domain (Django + uWSGI + AWS EC2)

Let’s walk through the fixes here—your core issue is that your Nginx server block isn’t set up to respond to your domain example.com, so it falls back to the default welcome page. Here’s how to resolve this:

1. Update Your Nginx Server Block

Your current server_name only includes the IPv4 address, which is why the IP works but the domain doesn’t. Edit your /etc/nginx/sites-enabled/mysite config to add your domain (and the www variant if you need it):

server {
 listen 80;
 server_name 123.45.67.89 example.com www.example.com; # Add your domain here

 #access_log /var/log/nginx/log/mysite.access.log;
 location = /favicon.ico {
 access_log off;
 log_not_found off;
 }
 location /static/ {
 root /home/ubuntu/proj/mysite;
 }
 location / {
 root /home/ubuntu/proj/mysite;
 # Side note: Since you're using uWSGI to serve Django, this index line is redundant
 # index /taxi/templates/taxi/index.html; 
 include /home/ubuntu/proj/mysite/uwsgi_params;
 uwsgi_pass unix:/run/uwsgi/mysite.sock;
 }
}

Quick tip: The index line in your / location isn’t needed here—Django handles routing (including serving your index page via views) through uWSGI. You can comment it out to avoid potential conflicts, but it’s not the root cause of your domain issue.

2. Disable Nginx’s Default Server Block

If the default Nginx server block is still enabled, it will catch requests that don’t match your custom server block (like your domain). Disable it with this command:

sudo unlink /etc/nginx/sites-enabled/default

3. Validate and Restart Nginx

Always check for configuration errors before restarting to avoid breaking your setup:

sudo nginx -t

If you see the message "test is successful", restart Nginx to apply your changes:

sudo systemctl restart nginx

4. Double-Check AWS Route 53 Configuration

Make sure your Route 53 hosted zone has an A record pointing example.com (and www.example.com if you use it) directly to your EC2 instance’s IPv4 address 123.45.67.89. You can verify this with:

dig example.com +short

It should return your EC2 IP. If not, wait a few minutes for DNS propagation—changes can take up to 10 minutes to fully roll out.

After completing these steps, your domain should load the same Django index page as your IP address.

内容的提问来源于stack exchange,提问作者HS Park

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:38:30