登录  | 加入社区

黑狼游客您好!登录后享受更多精彩

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

查看: 620|回复: 0

我的网站(摆设篇)

[复制链接]

180

主题

180

帖子

0

现金

黑狼菜鸟

Rank: 1

积分
0
发表于 2019-2-14 12:07:49 | 显示全部楼层 |阅读模式 来自 江苏徐州
媒介

我用的摆设情况是:centos7+nginx+uwsgi+python3+django。服务器和域名购买,以及 https 证书申请,都是在阿里云官网完成的(不是在打广告哦)。如今把整个摆设过程写一遍。感爱好的可以先看 uwsgi 官网内里的先容,人家讲得挺好的:

nginx and uWSGI are good choices for Django deployment...
A web server faces the outside world. It can serve files (HTML, images, CSS, etc) directly from the file system. However, it can’t talk directly to Django applications; it needs something that will run the application, feed it requests from web clients (such as browsers) and return responses.
A Web Server Gateway Interface - WSGI - does this job. WSGI is a Python standard.
uWSGI is a WSGI implementation. In this tutorial we will set up uWSGI so that it creates a Unix socket, and serves responses to the web server via the uwsgi protocol. At the end, our complete stack of components will look like this:
the web client the web server the socket  uwsgi  Django
第一步:安装 python3.x

centos7 只自带了 python2.x,以是 python3.x 得本身安装,为什么用 python3.x?纵观汗青往事物终会被新事物代替,而且如今 python3.x 已经成熟了。留意不要把 python2.x 删除了,差别版本是可以共存的,许多根本的下令、软件包都要依靠预装的 python2.x 。
1.安装 python3 之前先给 centos7 安装 python3 的编译依靠,防止出现各种非常。
yum install gcc-c++yum install wget openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel2.安装 python
下载到 /usr/local/src 路径下,然后解压
cd /usr/local/srcwget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgztar -zxf /usr/local/src/Python-3.6.3.tgz && cd Python-3.6.3在 /usr/local/ 下新建一个文件夹 python3,便于清楚管理,不建也行。然后安装。
mkdir /usr/local/python3./configure --prefix=/usr/local/python3make && make altinstall创建链接,方便终端中任何路径下直接利用 python3 和 pip3 下令
ln -s /usr/local/python3/bin/python3.6 /usr/bin/python3  ln -s /usr/local/python3/bin/pip3.6  /usr/bin/pip3在终端输入下令测试
python3表现如下,阐明安装乐成
[root@xxxxxxx ~]# python3Python 3.6.3 (default, Jul 23 2018, 13:51:42) [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linuxType "help", "copyright", "credits" or "license" for more information.大概读者会问,为什么不消 Anaconda ? 由于我买的服务器内存小,不想安装过多东西。
第二步:安装 nginx

yum install epel-releaseyum install nginx*   systemctl start nginxwhereis nginx假如欣赏器访问域名大概 ip 出现 Welcome to nginx! 则表现 Nginx 已经安装并运行乐成。


dD9Hyn6Oa5zAhoNK.jpg

第三步:安装假造情况管理工具 virtualenvwrapper

依次输入下面下令
yum install python-setuptools python-develpip install virtualenvwrapper //centos体系的下令然后找到 /root/.bashrc 文件添加两句代码,要否则直接利用创建假造情况下令会报错。
export WORKON_HOME=/.virtualenvssource /usr/bin/virtualenvwrapper.sh第四步:新建一个假造情况和安装 django

新建一个基于 Python3 的假造情况:
mkvirtualenv -p /usr/bin/python3 env3新建完后主动会进入 env3 中,安装 django
pip install django第五步:把当地编写好的 django 项目放到服务器上面

这里我是用 shell 6 和 xftp 6 把项目放到 home 下面。文件布局:
home
└── djangoWeb
   ├── djangoWeb
      ├── conf
      └── __pycache__
   ├── mysite
      ├── migrations
         └── __pycache__
      ├── __pycache__
      ├── static
         └── mysite
             ├── css
             ├── img
             ├── js
             ├── scss
             └── vendor
                 ├── bootstrap
                    ├── css
                    └── js
                 ├── fontawesome-free
                    ├── css
                    ├── js
                    ├── less
                    ├── scss
                    ├── sprites
                    ├── svgs
                       ├── brands
                       ├── regular
                       └── solid
                    └── webfonts
                 └── jquery
      └── templates
          └── mysite
   └── templates


ps: 实在 pycharm 另有自带的摆设到服务器上面的功能,这里就不先容了。
第六步:安装 uwsgi

按照 uwsgi 官网的来http://uwsgi.readthedocs.io/en/latest/tutorials/Django_and_nginx.html
pip install uwsgi然后新建一个 test.py 文件编辑内容如下,文件任意放一个位置,这里将它放在项目根目次下
# test.pydef application(env, start_response):    start_response('200 OK', [('Content-Type','text/html')])    return [b"Hello World"] # python3    #return ["Hello World"] # python2找到文件地点位置实行下令
uwsgi --http :8000 --wsgi-file test.py在欣赏器访问服务器 ip 和端口,打印出 “Hello World” 阐明安装乐成。
第七步:编辑 nginx 设置文件

部门模拟 uwsgi 官网
 /etc/nginx/nginx.conf
# the upstream component nginx needs to connect toupstream 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 serverserver {    # the port your site will be served on    listen      8000;    # the domain name it will serve for    server_name langlicun.com; # substitute your machine's IP address or FQDN    charset     utf-8;    # max upload size    client_max_body_size 75M;   # adjust to taste    # Django static    location /static {    alias /home/djangoWeb/static; # 指向djangostatic目次    }    # Finally, send all non-media requests to the Django server.    location / {    uwsgi_pass  django;    include     uwsgi_params; # the uwsgi_params file you installed    }}第八步:编辑 uwsgi 设置文件

在项目根路径下新建一文件夹 conf,添加一个 uwsgi.ini文件,内容编辑如下:
# mysite_uwsgi.ini file    [uwsgi]    # Django-related settings    # the base directory (full path)    chdir           = /home/djangoWeb/    # Django's wsgi file    module          = djangoWeb.wsgi    # the virtualenv (full path)    virtualenv = /.virtualenvs/env3    # 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第九步:网络静态文件



这步很紧张,把网站和背景 admin 的静态文件网络到同一个目次下。在项目标 /djangoWeb/settings.py 文件添加代码:


STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static/")然后实行下令:
python manage.py collectstatic

乐成后可以瞥见 djangoWeb 下面多了一个 static 文件夹,内里是全部必要的静态文件。
第十步:启动 nginx 和 uwsgi

前面已经设置好了,启动前先把项目里的 settings.py 编辑和添加:
DEBUG = FalseALLOWED_HOSTS = ['*']找到 uwsgi.ini 路径实行下令
uwsgi --ini uwsgi.ini以后可以直接利用下令
pkill -f uwsgi在直接实行下令
nginx欣赏器访问该域名,可以瞥见网页正常。
增补


  • 必要认识相干根本的 linux 下令
  • 升级 http 至 https 可以直接阿里云购买免费的证书,阿里云官网有对应的安装教程。
  3. 本身手动开辟和摆设一个网站也是挺简朴的,可以随意更改前端模板。




上一篇:大数据工程师高薪培训班_零底子入门学习大数据视频教程_大数据零底子入门视 ...
下一篇:云盘算Linux技能学习视频15.2Centos7网络设置文件
您需要登录后才可以回帖 登录 | 加入社区

本版积分规则

 

QQ|申请友链|小黑屋|手机版|Hlshell Inc. ( 豫ICP备16002110号-5 )

GMT+8, 2024-5-7 21:02 , Processed in 0.103033 second(s), 47 queries .

HLShell有权修改版权声明内容,如有任何爭議,HLShell將保留最終決定權!

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表