zoukankan      html  css  js  c++  java
  • nginx配置与重启

    1、uwsgi安装部署web服务:

    sudo /usr/local/bin/uwsgi --http-socket :9090

    2、苹果机修改hosts文件路径:/private/etc/hosts

    3、用这句话创建一个django项目,该目录里面包含各种配置文件:

    python django-admin.py startproject cmdb

    4、用这句话创建一个django项目,该目录里面包含模型和视图:

    python3 manage.py startapp assets

    5、检查端口是否被占用:lsof -i :8090

    6、用uwsgi运行项目:

    sudo /usr/local/bin/uwsgi --http-socket :8080 --chdir /data/cloud/deploy/src/funpu_daas_cmdb --module cmdb.wsgi

    7、网页测试项目test.py输出hello world失败原因分析:

    vim test.py

    # test.py

    def application(env, start_response):

        start_response(‘200 OK‘, [(‘Content-Type‘,‘text/html‘)])

        return [b"Hello World"] # python3

        #return ["Hello World"] # python2

    uwsgi --http :8001 --wsgi-file test.py

    此时访问http://localhost:8001可见Hello World,成功。

    (补:成功不易啊。为什么到处的教程都是写的return “xxxxx”,结果网页无输出,我跋山涉水找到官网才发现要加b,原因当然是版本不同,其中的[]加不加无所谓,但是在python3中,因为字符默认是unicode了,所以必须进行编码。

    8、快速收集static文件里面的文件:

    python3.6 manage.py collectstatic

    下面简单的介绍一下staticfiles的主要配置:

    1)  STATIC_ROOT:运行manage.py collectstatic后静态文件将复制到的目录。注意:不要把你项目的静态文件放到这个目录。这个目录只有在运行collectstatic时才会用到。我最开始想当然的以为这个目录和MEDIA_ROOT的作用是相同的,致使在开发环境下一直无法找到静态文件。

    2) STATIC_URL:设置的static file的起始url,这个只可以在template里面引用到。这个参数和MEDIA_URL的含义差不多。

    3)STATICFILES_DIRS:除了各个app的static目录以外还需要管理的静态文件位置,比如项目公共的静态文件差不多。和TEMPLATE_DIRS的含义差不多。

    4)各个APP下static/目录下的静态文件django的开发服务器会自动找到,这点和以前APP下的templates目录差不多。

    5)在urls.py中加入静态文件处理的代码

    9、nginx配置删除与重启:

    1)移除掉刚才安装的nginx

    执行:yum remove nginx

    2)添加Centos Nginx yum资源库

    执行:rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm Retrieving http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

    3)安装nginx

    执行:yum install -y nginx

    4)service nginx start   就可以看到启动成功啦

  • 相关阅读:
    PAT (Advanced Level) Practice 1055 The World's Richest (25 分) (结构体排序)
    PAT (Advanced Level) Practice 1036 Boys vs Girls (25 分)
    PAT (Advanced Level) Practice 1028 List Sorting (25 分) (自定义排序)
    PAT (Advanced Level) Practice 1035 Password (20 分)
    PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) (进制转换,回文数)
    PAT (Advanced Level) Practice 1120 Friend Numbers (20 分) (set)
    从零开始吧
    Python GUI编程(TKinter)(简易计算器)
    PAT 基础编程题目集 6-7 统计某类完全平方数 (20 分)
    PAT (Advanced Level) Practice 1152 Google Recruitment (20 分)
  • 原文地址:https://www.cnblogs.com/haoxinchen/p/9664476.html
Copyright © 2011-2022 走看看