Devinwon / article

0 stars 0 forks source link

云环境部署配置拓展(一)——日志及静态资源的配置 #4

Open Devinwon opened 6 years ago

Devinwon commented 6 years ago

对于云环境还不是很熟的,请确认你已经看过先前文章云环境部署 或已成功部署云环境,以免跳跃太大难以理解。

一. nginx.conf的拓展配置

说拓展,是相对我的云环境部署文章而言,对于老司机算不上...

1. 增加日志 一般我个人的nginx.conf就位于项目目录下,在server中进行添加日志字段,这里给出我的一个实例,供参考

server {
        listen       80;
        server_name  localhost;
    charset      utf-8;
        #将一下两行加到你的.conf中即可
    access_log      /home/programe/cloudms/nginx_access.log;
    error_log      /home/programe/cloudms/nginx_error.log;
    client_max_body_size 75M;

        location / {
            root   html;
            index  index.html index.htm;
       #new add in my project
        include /home/nginx/conf/uwsgi_params;
        uwsgi_pass  127.0.0.1:9000;

        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

nginx_access.log,nginx_error.log,没有手动建立的话,nginx启动会自动建立,记录的分别是访问成功与否的日志

2. 静态资源处理 静态资源一般位于项目工程的应用app目录下,现在项目中配置好,然后在nginx.conf中配置,实例如下

server {
        listen       80;
        server_name  localhost;
    charset      utf-8;
        #将一下两行加到你的.conf中即可
    access_log      /home/programe/cloudms/nginx_access.log;
    error_log      /home/programe/cloudms/nginx_error.log;
    client_max_body_size 75M;

        #以下这部分是对静态资源目录进行配置,注意服务器环境不同于开发环境
        #前置工作,需要在本地使用python manage.py collectstatic,自动将你开发中配置的静态文件全部
        #拷贝到项目根目录static(自动建立)下,用于服务器环境下存储静态资源,
       location /static {
               alias /home/programe/cloudms/static;
        }

        location / {
            root   html;
            index  index.html index.htm;
       #new add in my project
        include /home/nginx/conf/uwsgi_params;
        uwsgi_pass  127.0.0.1:9000;

        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

3. 查阅命令 netstat -antp|grep 80|grep ESTABLISHED -c4 查看Web服务器进程连接数 ps -ef|grep nginx|wc -l 查看Nginx运行进程数

4. setting配置参考 example of mine

STATIC_URL = '/static/'
#root of pro on server
STATIC_ROOT =  os.path.join(BASE_DIR,'static')
#more than one app,add to the follow
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "login\static"),
]