nginx:
upstream django {
# server unix:///path/to/your/mysite/mysite.sock; # for a file socket
server 127.0.0.1:8000; # for a web port socket (we'll use this first)
}
# configuration of the server
server {
# the port your site will be served on
listen 80;
# the domain name it will serve for
server_name 120.78.175.214 ; # substitute your machine's IP address or FQDN
charset utf-8;
#root /home/hwkjWeb/dist; #定义服务器的默认网站根目录位置
#index index.html; #定义index页面
#error_page 404 /index.html; #将404错误页面重定向到index.html可以解决history模式访问不到页面问题
# max upload size
client_max_body_size 75M; # adjust to taste
location = / {
root /home/hwkjWeb/dist/;
index index.html;
error_page 404 /index.html;
#uwsgi_pass django;
#include uwsgi_params; # the uwsgi_params file you installed
}
location ~* \.html {
root /home/hwkjWeb/dist/;
index index.html;
error_page 404 /index.html;
}
location / {
proxy_pass http://django;
proxy_set_header Host $http_host;
}
location ~* \.(css|js|jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|map|mp4|ogg|ogv|webm|htc)$ {
root /home/hwkjWeb/dist/;
index index.html;
error_page 404 /index.html;
expires 1M;
access_log off;
add_header Cache-Control "public";
}
location /public/ {
alias /home/hwkjWeb/dist/;
}
# Django media
location /media {
alias /home/hwkj/media/; # 指向django的media目录
}
location /static {
alias /home/hwkj/static/; # 指向django的static目录
}
# Finally, send all non-media requests to the Django server.
location /hwkj/ {
uwsgi_pass django;
include uwsgi_params; # the uwsgi_params file you installed
}
}
settings.py:
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
STATIC_ROOT = os.path.join(BASE_DIR, "static")
uwsgi:
# mysite_uwsgi.ini file
[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = /home/hwkj
# Django's wsgi file
module = hwkj.wsgi
# the virtualenv (full path)
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 10
# the socket (use the full path to be safe
socket = 127.0.0.1:8000
# ... with appropriate permissions - may be needed
# chmod-socket = 664
# clear environment on exit
vacuum = true
virtualenv = /root/.virtualenvs/hwkj
错误: