问题后期会有次序的整理,目前整理一小部分html
1.部署以后出现403问题。
403权限问题的修改:python
(1)打开nginx.conf文件mysql
vim /etc/nginx/nginx.conf
(2)按键盘“i”进入编辑模式,修改第一行为nginx
user root;
(3)按键盘“esc”退出键,输入:wq,保存并推出。git
(4)查看80端口占用pid值web
lsof -i tcp:80
(5)杀死pid=14012的进程sql
kill 14012
(6)启动nginxdjango
sudo /usr/sbin/nginx
查看页面是否显示正常vim
2.uwsgi的理解及简单使用?
uwsgi中文文档:http://uwsgi-docs-cn.readthedocs.io/zh_CN/latest/WSGIquickstart.htmlcentos
(1)简单运用-利用文件启动
新建uwsgitest.py的文件(python3+写法)
def application(env, start_response): start_response('200 OK', [('Content-Type','text/html')]) return [b"Hello World"]
放置在服务器某个目录下
在该目录运行
uwsgi --http :9090 --wsgi-file uwsgitest.py
能够看到打出的文字,uwsgi起做用,可是关闭终端后,没法显示。
须要新建uswgi.ini文件,并设定开机启动
uwsgi.ini
[uwsgi] socket = 127.0.0.1:9090 chdir = /root/projects/ wsgi-file = py_rest/uwsgitest.py processes = 4 threads = 2 stats = 127.0.0.1:9191
更新ini文件
uwsgi -i /root/projects/py_rest/uwsgi.ini &
(2)django的uwsgi设置
其中,conf目录下2文件和uwsgi_params为必须文件(py_rest/uwsgi.ini和py_uwsgitest.py为上文必须文件)
conf目录下放置本项目nginx和uwsgi配置文件
uc_nginx.conf
upstream django { # server unix:///path/to/your/mysite/mysite.sock; # for a file socket server 127.0.0.1:80; # for a web port socket (we'll use this first) } server { listen 80; # 监听端口 server_name xx.xxx.xx.xx; # 填写你的服务器 charset utf-8; autoindex on; # 资源限制 client_max_body_size 75M; # adjust to taste client_header_buffer_size 16k; # Django media资源 location /media { alias /root/projects/py_rest/media; # 指向django的media目录 } # Django static资源 location /static { alias /root/projects/py_rest/static; # 指向django的static目录 } # 日志 access_log /root/projects/py_rest/access_log; error_log /root/projects/py_rest/error_log; location / { # A.静态页面 # root /root/projects/py_rest/templates; # index index index.html urls.py; # B.django项目 uwsgi_pass 127.0.0.1:8000; #这个和uwsgi中的socket要一致 include uwsgi_params; # C.其余设置 # autoindex on; # autoindex_exact_size on; autoindex_localtime on; } }
uwsgi.ini
# py_rest.ini file [uwsgi] # Django的项目全路径 chdir = /root/projects/py_rest # Django's wsgi文件 #module = py_rest.wsgi wsgi-file = py_rest/wsgi.py master = true processes = 10 # socket链接 socket = 127.0.0.1:8000 # 这个和uc_nginx.conf中的uwsgi_pass要一致 vacuum = true # 退出uwsgi是否清理中间文件,包含pid、sock和status文件 procname-prefix-spaced= py_rest # uwsgi的进程名称前缀 py-autoreload=1 # py文件修改,自动加载 # 虚拟环境路径 home = /root/.virtualenvs/testvir3 virtualenv = /root/.virtualenvs/testvir3 # 日志 logto = /tmp/mylog.log
文件上传到服务器上
uswgi_prama(重要,ini文件设置location / {include uwsgi_params;}时须要该文件的路径,如本例所示就要在chdir设置的目录下,也就是 /root/projects/py_rest目录下。如过放到别的路径下,include后面须要给路径
uwsgi_param QUERY_STRING $query_string; uwsgi_param REQUEST_METHOD $request_method; uwsgi_param CONTENT_TYPE $content_type; uwsgi_param CONTENT_LENGTH $content_length; uwsgi_param REQUEST_URI $request_uri; uwsgi_param PATH_INFO $document_uri; uwsgi_param DOCUMENT_ROOT $document_root; uwsgi_param SERVER_PROTOCOL $server_protocol; uwsgi_param UWSGI_SCHEME $scheme; uwsgi_param REMOTE_ADDR $remote_addr; uwsgi_param REMOTE_PORT $remote_port; uwsgi_param SERVER_PORT $server_port; uwsgi_param SERVER_NAME $server_name;
1) conf更新
cd /etc/nginx/conf.d/ rm uc_nginx.conf sudo ln -s /root/projects/py_rest/conf/nginx/uc_nginx.conf /etc/nginx/conf.d/ lsof -i tcp:80 kill 12344 sudo /usr/sbin/nginx
2) ini更新
uwsgi -i /root/projects/py_rest/conf/uwsgi.ini &
查看页面已经能够刷出
因为设置的是80端口,在浏览器里输入主机ip就能够看到主页内容
不过对静态资源的加载出现问题,须要设置。
3.ImportError: No module named 'MySQLdb'
解决1:
路径:/root/.virtualenvs/env_rest/lib/python3.5/site-packages/django/db/backends/mysql/base.py
vim /usr/lib/python3.5/site-packages/django/db/backends/mysql/base.py
在from django.utils.safestring import SafeBytest,SafeTest下添加下面两条
import pymysql pymysql.install_as_MySQLdb()
结果:运行会报错
解决2:
wget http://sourceforge.net/projects/mysql-python/files/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz tar zxf MySQL-python-1.2.3.tar.gz && cd MySQL-python-1.2.3 python2 setup.py build python2 setup.py install
centos提示ImportError: No module named MySQLdb解决办法:https://lvtao.net/server/645.html
结果
1.nginx出现403 Forbidden解决方法:https://www.cnblogs.com/Alex-as/p/8963505.html
2.nginx 403 forbidden 二种缘由:https://blog.csdn.net/u011650048/article/details/54092881
3.项目部署(nginx + uwsgi + django) 和 开机自启动django项目:http://www.javashuo.com/article/p-odmkibop-mn.html
4.uwsgi使用介绍:https://www.jianshu.com/p/c3b13b5ad3d7
5.python3.*报“ImportError: No module named ‘MySQLdb'”:https://www.cnblogs.com/TaleG/p/6735099.html