在Redhat 7中使用AWS微实例,默认为python 2.7.5,django 1.7。部署简单的mysite项目会抛出错误。
禁止
您无权访问此服务器上的内容。
以下是用于创建django项目并进行部署的简单过程。
Using username "ec2-user".
Authenticating with public key "imported-openssh-key"
Last login: Fri Sep 26 10:43:08 2014 from 14.141.162.198
[ec2-user@ip-172-31-1-245 ~]$ mkdir django
[ec2-user@ip-172-31-1-245 ~]$ cd django
[ec2-user@ip-172-31-1-245 django]$ django-admin startproject mysite
[ec2-user@ip-172-31-1-245 django]$ cd mysite/
[ec2-user@ip-172-31-1-245 mysite]$ mkdir apache
以下是django.wsgi的内容
[ec2-user@ip-172-31-1-245 mysite]$ vim apache/django.wsgi
import os, sys
sys.path.append('/home/ec2-user/django')
sys.path.append('/home/ec2-user/django/mysite')
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
以下是文件的许可
[ec2-user@ip-172-31-1-245 django]$ cd /home/ec2-user/
[ec2-user@ip-172-31-1-245 ~]$ ls -lR django
django:
total 0
drwxrwxr-x. 4 ec2-user ec2-user 48 Sep 26 13:51 mysite
django/mysite:
total 4
drwxrwxr-x. 2 ec2-user ec2-user 24 Sep 26 13:53 apache
-rwxr-xr-x. 1 ec2-user ec2-user 249 Sep 26 13:50 manage.py
drwxrwxr-x. 2 ec2-user ec2-user 70 Sep 26 13:50 mysite
django/mysite/apache:
total 4
-rw-rw-r--. 1 ec2-user ec2-user 251 Sep 26 13:53 django.wsgi
django/mysite/mysite:
total 12
-rw-r--r--. 1 ec2-user ec2-user 0 Sep 26 13:50 __init__.py
-rw-r--r--. 1 ec2-user ec2-user 2042 Sep 26 13:50 settings.py
-rw-r--r--. 1 ec2-user ec2-user 275 Sep 26 13:50 urls.py
-rw-r--r--. 1 ec2-user ec2-user 387 Sep 26 13:50 wsgi.py
以下是添加到apache配置文件的附加配置。
[ec2-user@ip-172-31-1-245 ~]$ sudo vim /etc/httpd/conf/httpd.conf
<VirtualHost *:80>
ServerName www.example.com
ServerAlias www.example.com
WSGIScriptAlias / /home/ec2-user/django/mysite/apache/django.wsgi
<Directory /home/ec2-user/django/mysite/apache>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
重新启动apache服务后,在浏览器中它抛出了Forbidden错误。
[ec2-user@ip-172-31-1-245 ~]$ sudo service httpd restart
Redirecting to /bin/systemctl restart httpd.service
请帮助解决权限问题。如果您需要任何其他信息,请与我们联系。