Apache服务器上提供的Django站点无法正常工作,日志没有错误 [英] Django site served on Apache server doesn't work, logs have no error
问题描述
我在服务器中的/home/rohit/django-site/infer
有一个Django网站. apache2
和wsgi
已经安装并且可以正常工作.要看到这一点:
I've a Django website located at /home/rohit/django-site/infer
, in a server. apache2
and wsgi
are already installed and working correctly. To see that:
$ systemctl status apache2.service
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Drop-In: /lib/systemd/system/apache2.service.d
└─apache2-systemd.conf
Active: active (running) since Fri 2019-05-03 19:12:34 IST; 31min ago
Process: 9354 ExecStop=/usr/sbin/apachectl stop (code=exited, status=0/SUCCESS)
Process: 9364 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
Main PID: 9368 (apache2)
Tasks: 24 (limit: 4915)
CGroup: /system.slice/apache2.service
├─9368 /usr/sbin/apache2 -k start
├─9370 /usr/sbin/apache2 -k start
├─9371 /usr/sbin/apache2 -k start
├─9372 /usr/sbin/apache2 -k start
├─9373 /usr/sbin/apache2 -k start
├─9374 /usr/sbin/apache2 -k start
└─9375 /usr/sbin/apache2 -k start
这是/var/log/apache2/error.log
的内容:
[Fri May 03 17:04:03.885793 2019] [mpm_prefork:notice] [pid 24349] AH00163: Apache/2.4.29 (Ubuntu) mod_wsgi/4.5.17 Python/3.6 configured -- resuming normal operations
[Fri May 03 17:04:03.885868 2019] [core:notice] [pid 24349] AH00094: Command line: '/usr/sbin/apache2'
[Fri May 03 19:12:34.361607 2019] [mpm_prefork:notice] [pid 24349] AH00169: caught SIGTERM, shutting down
[Fri May 03 19:12:34.480584 2019] [mpm_prefork:notice] [pid 9368] AH00163: Apache/2.4.29 (Ubuntu) mod_wsgi/4.5.17 Python/3.6 configured -- resuming normal operations
[Fri May 03 19:12:34.480660 2019] [core:notice] [pid 9368] AH00094: Command line: '/usr/sbin/apache2'
看着哪一点,我知道一切都很好.
Looking at which, I understand that everything is okay.
/var/log/apache2/access.log
是空的,这意味着我对站点的所有请求甚至都没有到达服务器.似乎是防火墙问题.
The /var/log/apache2/access.log
is empty though, which means that all the requests made by me for the site didn't even reach the server. That seems like a firewall issue.
防火墙
防火墙专门允许从外部访问端口8000
.这意味着即使端口80
(http
)也不允许从外部访问.
The firewall has specifically allowed port 8000
to be accessed from outside world. That means that even port 80
(http
) isn't allowed to be accessed from the outside world.
为了进行测试,我从服务器上运行了./manage.py runserver 0.0.0.0:8000
,并通过访问<ip-of-server>:8000
从笔记本电脑成功访问了该站点.这意味着可以从外部访问端口8000
.
To test that, I ran ./manage.py runserver 0.0.0.0:8000
from the server, and successfully accessed the site from my laptop, by visiting <ip-of-server>:8000
. That means that port 8000
is accessible from outside.
现在,为确保apache可以在该端口上运行,我编辑了文件/etc/apache2/sites-available/000-default.conf
,该文件现在看起来像:
Now, to make sure that apache serves on this port, I edited the file /etc/apache2/sites-available/000-default.conf
, which now looked like:
<VirtualHost *:8000>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /static /home/rohit/django-site/infer/static
<Directory /home/rohit/django-site/infer/static>
Require all granted
</Directory>
<Directory /home/rohit/django-site/infer/infer>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess infer python-path=/home/rohit/django-site/infer python-home=/home/rohit/django-site/inferenv
WSGIProcessGroup infer
WSGIScriptAlias / /home/rohit/django-site/infer/infer/wsgi.py
</VirtualHost>
因此,完成所有这些操作后,当我在浏览器中放置地址<ip-of-server>:8000
时,出现无法连接"错误.另外,空的access.log
表示请求从未到达服务器.但是端口8000
是开放的,因此防火墙不应该成为问题.那么,有什么可能会引起问题吗?
So, after doing all this, when I put the address <ip-of-server>:8000
on my browser, I get an "unable to connect" error. Plus, the empty access.log
means that the request never reached the server. But port 8000
is open, so the firewall shouldn't be the problem. So, is there anything that might be causing the problem?
感谢您的帮助!
推荐答案
正如 Daniel Roseman 所评论的那样,在/etc/apache2/sites-available/000-default.conf
中添加了Listen 8000
.
As commented by Daniel Roseman, I added Listen 8000
to the /etc/apache2/sites-available/000-default.conf
.
我还需要允许访问项目的主目录.因此,根据 MaximeK
I also needed to allow access to my project's home directory. So I added the following to /etc/apache2/apache2.conf
, as suggested by MaximeK
<Directory /home/rohit/django-site/infer>
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order deny,allow
Allow from all
</Directory>
然后,按照此答案的建议,通过以下方式更改了/home/rohit/django-site/infer
的权限:
Then I changed the permissions for /home/rohit/django-site/infer
, as suggested by this answer, by:
sudo chmod -R 755 <site_top_folder>
这篇关于Apache服务器上提供的Django站点无法正常工作,日志没有错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!