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 <signing-key@nginx.com>
---------------------------------------------------------------------------------------------------------
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';
---------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------
必須要開啟系統(tǒng)升級 Ubuntu
使用python開發(fā)源? apt-get install python3-dev