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

更换PC后Fedora 23虚拟机中Apache无法部署Django站点

Hey there, let's work through this issue you're facing with your migrated Fedora 23/Apache VM. The fact that hostname -f returns "localhost" is a big clue here—let's break down the fixes step by step:

1. Fix Apache's Listening Configuration

First off, your Apache might be only binding to the loopback address (127.0.0.1), which is why non-local requests aren't getting through:

  • Open your httpd.conf file with a text editor: vi /etc/httpd/conf/httpd.conf
  • Look for the Listen directive. If it's set to Listen 127.0.0.1:80, change it to Listen 0.0.0.0:80 (this tells Apache to listen on all available network interfaces) or explicitly specify your VM's actual IP address like Listen 192.168.x.x:80
  • Restart Apache to apply changes: systemctl restart httpd.service
2. Correct Hostname & FQDN Settings

A hostname -f result of "localhost" means your system doesn't have a proper Fully Qualified Domain Name (FQDN) configured, which can throw off service bindings and network recognition:

  • Edit /etc/hostname and set a meaningful FQDN, for example: fedora-django.local
  • Update /etc/hosts to map your VM's IP to this new hostname. Add a line like:
    192.168.x.x  fedora-django.local  fedora-django
    
    Replace 192.168.x.x with your VM's actual network IP address
  • Apply the hostname change immediately with: hostnamectl set-hostname fedora-django.local
  • Verify it worked by running hostname -f again—it should now return your new FQDN
3. Update Django's ALLOWED_HOSTS

Django will reject requests from addresses not listed in its ALLOWED_HOSTS setting, even if Apache is listening correctly:

  • Open your Django project's settings.py file
  • Modify the ALLOWED_HOSTS line to include your VM's IP, hostname, and localhost for testing:
    ALLOWED_HOSTS = ['192.168.x.x', 'fedora-django.local', 'localhost']
    
  • Restart your Django application (or the Apache/mod_wsgi service if you're using that deployment method)
4. Rule Out Network & Firewall Issues

Don't forget the basics:

  • Ensure your VM is using bridge network mode (this lets it get an IP on the same network as your new host computer—NAT or host-only modes can cause connectivity blocks)
  • Ping your VM's IP from your new host to confirm network connectivity. If ping fails, troubleshoot your VM's network setup first
  • Check Fedora's firewall (firewalld) to make sure HTTP traffic is allowed:
    firewall-cmd --add-service=http --permanent
    firewall-cmd --reload
    

To answer your original question: Yes, updating /etc/hosts and httpd.conf is absolutely part of the solution, but you'll also need to address the Django settings and network/firewall checks to get everything working properly.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 08:37:47