1.alias虚拟目录配置下,访问http://www.colorgg.com/huan/a.html实际指定的是/home/www/huan/a.html

示例一
location /huan/ {
      alias /home/www/huan/;
}

alias指定的目录后面必须要加上"/",即/home/www/huan/不能改成/home/www/huan

2.nginx就会去/home/www/huan下寻找http://www.colorgg.com/huan的访问资源,两者配置后的访问效果是一样的!

location /huan/ {
       root /home/www/;
}


 

3.STATIC_URL, STATIC_ROOT, STATICFILES_DIRS 

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)

 

python manage.py collectstatic做了什么
Collects the static files into STATIC_ROOT.
翻译:把静态文件收集到 STATIC_ROOT中。

STATIC_URL的作用
URL to use when referring to static files located in STATIC_ROOT.
Example: “/static/” or “http://www.example.com/static/”
翻译:STATIC_URL用于引用STATIC_ROOT所指向的静态文件。


STATIC_ROOT的作用:
当执行collectstatic命令时,会将静态文件拷贝到STATIC_ROOT所指定的目录,MEDIA_ROOT同理
nginx的 location /static/应该指向的是 STATIC_ROOT所在的目录

#以下不是必须的
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
) 

 4. nginx的配置[root@slave1 conf.d]# cat myserver.conf

server {
  
    listen 80;
    client_max_body_size 4G;

   
    server_name example.com 121.211.117.79 www.example.com;

    keepalive_timeout 5;

    access_log  /var/log/nginx/access.log ;
    error_log  /var/log/nginx/errors.log warn;
    location / {
      proxy_pass http://app_server1;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header Host $http_host;

      proxy_redirect off;

    }

location /media  {
    alias /opt/sudjango/nginxdjango/media;
  }
 
  location /static {
    alias /opt/sudjango/nginxdjango/static;
  }

    error_page 500 502 503 504 /500.html;
    location = /500.html {
      root /path/to/app/current/public;
    }
  }

5. upstream.conf

[root@slave1 conf.d]# cat wltupstream.conf 
upstream app_server1 {
   
     server 10.0.0.11:8000 ;
     sticky;
  }
[root@slave1 conf.d]#

 

用一个例子来演示会更加清晰



阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6
标签: nginxgo