简体   繁体   中英

Django 1.10, Apache 2.4 Serving Basic App on CentOS7 Getting 403 Forbidden to /

Screwing around at this point just to try and get it working.

I am getting a 403 Forbidden: You don't have permission to access / on this server. error. I have been following this guide on how to setup Apache to work with CentOS and Django:

https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-centos-7

Also, read several questions on SO regarding the error, but none have resolved the problem.

Fresh Django project install so should just be showing the static "it's working page" at localhost:8000 , I would think.

/etc/httpd/conf.d/django_test.conf

Alias /static /home/dev/testserver/static
<Directory /home/dev/testserver/static>
  Require all granted
</Directory>

<Directory /home/dev/testserver/testserver>
  <Files wsgi.py>
     Require all granted
  </Files>
</Directory>

WSGIDaemonProcess testserver python-path=/home/dev/testserver:/home/venvs/django/lib/python3.6/site-packages
WSGIProcessGroup testserver
WSGIScriptAlias / /home/dev/testserver/testserver/wsgi.py

I am pretty naive when it comes to this, but do I or don't I have to run python manage.py runserver in addition to having HTTPD setup? Or does that only apply to if you are developing locally using the built in Django server?

Speaking of which, I can visit the page on the remote server using the built in Django server, but understand this highly undesirable.

I do have port 80 open and can see that it is listening for traffic.

Per the tutorial I gave the /home/dev directory chmod 710 permissions and added apache to the same user group as the owner of the directory.

Just not seeing what I am doing wrong.

EDIT #1

I started just going through /etc/httpd/conf/httpd.conf line by line to see if anything looked add. For group I changed it from apache to sqladmin because I added the apache user to that group. Also, made sure that LoadModule wsgi_module modules/mod_wsgi.so was explicitly added. Still no luck.

At any rate I am now reading about the pip package for mod_wsgi to see if that might resolve my problems.

EDIT #2

The error_log says the following:

[Tue Jan 31 16:26:31.961512 2017] [core:error] [pid 4561] (13)Permission denied: [client 192.168.1.39:57651] AH00035: access to / denied (filesystem path '/home/dev/testserver/testserver/wsgi.py') because search permissions are missing on a component of the path

[Tue Jan 31 16:26:31.986965 2017] [core:error] [pid 4561] (13)Permission denied: [client 192.168.1.39:57651] AH00035: access to /favicon.ico denied (filesystem path '/home/dev/testserver/testserver/wsgi.py') because search permissions are missing on a component of the path, referer: http://192.168.1.4/

Says a permission error, but as far as I know it should only be looking at /home/dev and /home/venvs . All of which have the same permissions applied as does /home . The user apache exists, and the user apache is part of the sqladmin group which is the group on all of these directories and files. I went as far as to create an apache group and make sqladmin a part of that.

List of the directory permissions:

drwxr-xr-x.  3 sqladmin sqladmin   24 Jan 31 15:08 dev
drwx------. 14 sqladmin sqladmin 4096 Jan 30 21:13 sqladmin
drwxr-xr-x.  3 sqladmin sqladmin   20 Jan 31 15:05 venvs

... do I or don't I have to run python manage.py runserver in addition to having HTTPD setup?

You don't never do manage.py runserver in production besides you don't need it either. That's the whole point of setting up apache

Next let's look at this:

 WSGIDaemonProcess testserver python-path=/home/dev/testserver:/home/venvs/django/lib/python3.6/site-packages

Though you have set the permissions for your home directory. What about the /home/venvs directory? that sounds like an entirely different user account. So have you changed the permissions and the groups accordingly for that one?

Secondly, you will need to make te /home/dev/testserver folder readable by apache as well and also executable. The execute flag on a directory is needed for a user to change into that directory. Often times you find that permissions are changed accidentally while the project is being transferred to the server.

Well, whether or not it is considered a solution because I never did get Apache + mod_wsgi working, but I did get it working through PyPi mod_wsgi .

Installed into the virtualenv and just followed the "Using mod_wsgi-express with Django" section.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM