sudo apt-get update sudo apt-get upgrade
sudo apt-get install nginx sudo /etc/init.d/nginx start (start能够改为restart/stop) #或是sudo service nginx start 而后浏览器输入服务器IP,观察是否有welcom to nginx!
sudo apt-get install git python3 python3-pip sudo pip3 install virtualenv
$ gedit ~/.bashrc #gedit .bash_aliases 在顶部加入一行alias python=python3 $ source ~/.bashrc #或是source ~/.bash_aliases o $ python --version 就会发现是Python 3.5.2啦 /*or Open your .bashrc file nano ~/.bashrc. Type alias python=python3 on to a new line at the top of the file then save the file with ctrl+o and close the file with ctrl+x. Then, back at your command line type source ~/.bashrc. Now your alias should be permanent. */
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100 sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 150
切换Python2为默认版本:html
sudo update-alternatives --config python
cd /var/www sudo virtualenv env35
sudo git clone https://github.com/KyrieWang233/homework_submission-master.git source env35/bin/activate cd home... sudo pip3 install -r requirements.txt
sudo python manage.py collectstatic sudo python manage.py migrate python manage.py createsuperuser sudo vim settings.py将其中的ALLOWED_HOST=[*]改成本身的IP 而后输入 python manage.py runserver 0.0.0.0:8000
sudo pip3 install uwsgi uwsgi --http :8000 --module homework_submission.wsgi
[uwsgi] chdir=/var/www/homework_submission-master module=homework_submission.wsgi home=/var/www/env35 master=True processes=10 socket= :8001 chmod socket=666 vacuum=True max-requests=5000
upstream django{ server 127.0.0.1:8001; } server { listen 80; server_name sast.nymrli.top; charset utf-8; client_max_body_size 75M; location /static{ alias /var/www/homework_submission-master/static; } location /{ uwsgi_pass django; include /var/www/uwsgi_params; } }
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 REQUEST_SCHEME $scheme; uwsgi_param HTTPS $https if_not_empty; uwsgi_param REMOTE_ADDR $remote_addr; uwsgi_param REMOTE_PORT $remote_port; uwsgi_param SERVER_PORT $server_port; uwsgi_param SERVER_NAME $server_name;
cd /etc/nginx cd sites-enabled rm default ln -s /var/www/nginx.conf homework_submission ls
/etc/init.d/nginx restart
python
cd /var/www uwsgi --ini uwsgi.ini
vim /etc/rc.local(注意非虚拟环境也得安装uwsgi模块)nginx
添加下面代码: /usr/local/bin/uwsgi --ini /var/www/uwsgi.ini exit 0
在uwsgi.ini中加入git
py-autoreload=1
github重启一下:
killall -9 uwsgi
、/usr/local/bin/uwsgi --ini /var/www/uwsgi.ini
shell
关于etc/ linit. ddjango
若是你使用过inux系统,那么你必定据说过 init. d目录,这个目录究竟是干吗的呢?它归根结底只作了一件事情,但这件事情非同小可,是为整个系统作的,所以它很是重要。init.d目录包含许多系统各类服务的启动和中止脚本ubuntu
关于 /etc/rc.localvim
rc.local也是我常常使用的一个脚本,该脚本是在系统初始化级别脚本运行以后再执行的,所以能够安', '地在里面添加你想在系统启动以后执行的脚本.浏览器
总结
Linux是灵活的,正由于它的灵活性,咱们老是能够找到许多不一样的办法来解决同一个问题,服务的例子就是一个很好的佐证,有了 /etc/init.d目录下的脚本,再加上 /etc/rc. local这个利器,你能够放心的确保你的服务能够完美的启动和运行