Django-Ubuntu-Nginx-Uwsgi-Mysql Server INSTALLATION
Ubuntu 18.04.4 LTS / Nginx 1.18.0 / Django 2.2 / Pandas 1.02 /Nvd3 3.12/ Gcc 7.04 /MYSQL 14.14-D 5.7.30
1.Pycharm installation => copy file to folder => run ./pycharm.sh in /bin
2.install git=> sudo get-apt install git
3.sudo apt install python3
4.environment
sudo apt install python3-pip
sudo apt-get install python-dev
pip3 install django==2.2
pip3 install pymysql
sudo apt-get install mysql-server
pip3 install django-nvd3
pip3 install django-bower
5.set up mysql=> create db, user
6.pip3 install pandas
7. install nginx =>www.nginx.org
8. pip3 install uwsgi
9. set up config.conf / uwsgi.ini
10 config nginx => sudo nginx -t -c config.config (test first)
11. Start=> uwsgi -- ini /absolutepath
Stop=> uwsgi --stop uwsgi.pid
Start=> sudo nginx -s reload
Stop=> sudo nginx -s quit
------------------------------------------------------------------------------------------------------------------------------------------------
安装Nginx / MYSQL / Uwsgi
Nginx尽量不要使用systemctl 有可能导致无法正常加载启动配置文件 -t 测试 -c configpath 加载配置文件启动
编辑 :config.conf / uwsgi.ini / uwsgi.log / uwsgi.pid
首先编辑cofig 解决static文件 然后运行测试 需要 nginx -c 加载 config文件- 测试
使用绝对路径 /文件都在nginx目录下
------------------------------------------------------------------------------------------------------------------------
uwsgi.ini设置
[uwsgi]
#所使用Nginx连接时使用
socket=0.0.0.0:8000
#直接作为web服务器使用#
#http=0.0.0.0:8000
#配置工程目录
chdir=/home/brown/PycharmProjects/auslinkerp-linux2nd
#配置WSGI目录 相对路径 程序入口
wsgi-file=auslinkerp/wsgi.py
processes=4
threads=2
enable-threads=True
master=True
pidfile=uwsgi.pid
daemonize=uwsgi.log
-----------------------------------------------------------------------------------------------------------------------------
config.conf 设置
server {
listen 80;
server_name localhost;
root /home/brown/PycharmProjects/auslinkerp-linux2nd;
location /static {
alias /home/brown/PycharmProjects/auslinkerp-linux2nd/static;
}
location / {
include /etc/nginx/uwsgi_params;
uwsgi_pass 127.0.0.1:8000;
}
}
----------------------------------------------------------------------------------------------------------------------------------
其他需要注意的:
import pymysql
pymysql.version_info = (1, 3, 13, "final", 0)
pymysql.install_as_MySQLdb()
------------------------------------------------------------------------------------
关闭uwsgi =》 重启nginx =》再次启动uwsgi
启动 Uwsgi =>uwsgi --ini /home/brown/PycharmProjects/auslinkerp/uwsgi.ini
停止 Uwsgi=> uwsgi --stop uwsgi.pid
重启reload nginx =-> sudo nginx -s reload
退出d$ sudo nginx -s quit
检查进程$ ps -ef|grep nginx
------------------------------------------------------------------------------------
启动mysql -- sudo systemctl start mysql
开机自动启动 sudo systemctl enable mysql
---------------------------------------------------------------------------------------
安装服务器Ubuntu-Nginx
Install the prerequisites:
sudo apt install curl gnupg2 ca-certificates lsb-release
-----------------------------------------------------------------------------------------
To set up the apt repository for stable nginx packages,
echo "deb http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" \
| sudo tee /etc/apt/sources.list.d/nginx.list
----------------------------------------------------------------------------------------------
If you would like to use mainline nginx packages,
run the following command instead:
echo "deb http://nginx.org/packages/mainline/ubuntu `lsb_release -cs` nginx" \
| sudo tee /etc/apt/sources.list.d/nginx.list
----------------------------------------------------------------------------------------------------
Next, import an official nginx signing key so apt could verify the packages
authenticity:
curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo apt-key add -
Verify that you now have the proper key:
sudo apt-key fingerprint ABF5BD827BD9BF62
The output should contain the full fingerprint573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62as follows:
pub rsa2048 2011-08-19 [SC] [expires: 2024-06-14]
573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62
uid [ unknown] nginx signing key
---------------------------------------------------------------------------------------------------------
To install nginx, run the following commands:
sudo apt update
sudo apt install nginx
-----------------------------------------------------------------------------------------------------
sudo pip install django==1.3.3
-----------------------------------------------------------------------------------------------------
数据库 配置用户和密码 需要授权
create user 'django'@'localhost' identified by 'django-user-password';
grant usage on *.* to 'django'@'localhost';
grant all privileges on django-database-1.* to 'django'@'localhost';
---------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------
必须要开启系统升级 Ubuntu
使用python开发源 apt-get install python3-dev