wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz
tar -xvf Python-3.6.0.tgz
sudo mkdir /usr/local/python3
./configure --prefix=/usr/local/python3
make
sudo make install
1、修改舊版本 sudo mv /usr/bin/python /usr/bin/python_bak 2、建立新的軟鏈接 sudo ln -s /usr/local/python3/bin/python3 /usr/bin/python
3、檢查python的版本 python -V python-3.6.0 軟鏈接建立成功
6安裝pip3python
sudo apt install python3-pip
sudo ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
能夠試試 pip3 -V 是對應哪一個版本的python
sudo pip3 install django
須要用pip3
進入/data文件夾,建立名爲「helloworld」的項目 cd /data sudo django-admin startproject helloworld
修改 /data/helloworld/helloworld/settings.py 文件權限爲其它人可寫nginx
sudo chmod 666 /data/helloworld/helloworld/settings.py
ALLOWED_HOSTS = []
修改成
ALLOWED_HOSTS = ["115.159.157.136"]
,這樣能夠容許經過 ip 訪問
cd helloworld
sudo python manage.py runserver 0.0.0.0:8080
http://115.159.157.136:8080/
sudo python manage.py startapp learn
修改 helloworld/helloworld/settings.pyweb
# Application definition INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'learn', ]
sudo chmod 666 /data/helloworld/learn/views.py
編輯內容django
from django.http.response import HttpResponse def hello(request): user = request.GET.get('user') if not user: user = 'world' return HttpResponse('hello %s' % user)
修改 /data/helloworld/helloworld/urls.py 文件權限爲其它人可寫,而且修改成瀏覽器
sudo chmod 666 /data/helloworld/helloworld/urls.py
from django.contrib import admin
from django.urls import path服務器
from learn import views as learn_viewssession
urlpatterns = [
path('admin/', admin.site.urls),
path('hello',views.hello),
]app
sudo python manage.py runserver 0.0.0.0:8080 http://115.159.157.136:8080/hello http://115.159.157.136:8080/hello?user=test
1使用 pip 安裝 uwsgisocket
sudo pip install uwsgi
建立文件 /data/helloworld/uwsgi.ini ,並修改權限爲其它人可寫測試
sudo touch /data/helloworld/uwsgi.ini
sudo chmod 666 /data/helloworld/uwsgi.ini
編輯輸入如下內容
[uwsgi] chdir = /data/helloworld module = helloworld.wsgi socket = 127.0.0.1:8080 master = true vhost = true no-site = true workers = 2 reload-mercy = 10 vacuum = true max-requests = 1000 limit-as = 512 buffer-size = 30000 pidfile = /tmp/uwsgi.pid daemonize = /tmp/uwsgi.log
找到uwsgi所在位置,並加入環境變量
whereis uwsgi 獲得結果:uwsgi: /usr/local/bin/uwsgi export PYTHONPATH=/usr/local/bin 啓動uwsgi uwsgi --ini /data/helloworld/uwsgi.ini
sudo apt-get install nginx -y
建立文件 /etc/nginx/sites-enabled/helloworld.conf ,並修改權限爲其它人可寫
sudo touch /etc/nginx/sites-enabled/helloworld.conf
sudo chmod 666 /etc/nginx/sites-enabled/helloworld.conf
server { listen 80; server_name 115.159.157.136; charset utf-8; location / { uwsgi_pass 127.0.0.1:8080; include /etc/nginx/uwsgi_params; client_max_body_size 10m; } client_body_timeout 3m; send_timeout 3m; proxy_send_timeout 3m; proxy_read_timeout 3m; }
sudo systemctl restart nginx
http://115.159.157.136/hello