[学习笔记]ubuntu16.04编译安装nginx

更新源

  • sudo apt update

安装需要的依赖

  • sudo apt install build-essential
  • sudo apt install libtool
  • sudo apt install libpcre3 libpcre3-dev
  • sudo apt install zlib1g-dev
  • sudo apt-get install openssl libssl-dev

下载nginx源码包

  • wget http://nginx.org/download/nginx-1.13.10.tar.gz
  • tar zxvf nginx-1.13.10.tar.gz
  • cd nginx-1.13.10
  • ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-file-aio --with-http_realip_module
  • make
  • sudo make install

1.在系统服务目录里创建nginx.service文件

  • sudo vi /lib/systemd/system/nginx.service

[Unit]
Description=nginx
After=network.target
  
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
  
[Install]
WantedBy=multi-user.target

设置开机启动

  • sudo systemctl enable nginx.service

启动nginx服务

  • sudo systemctl start nginx.service 


查看服务当前状态

  • sudo systemctl status nginx.service

重新启动服务

  • sudo systemctl restart nginx.service 

查看所有已启动的服务

  • sudo systemctl list-units --type=service

安装django python web开发框架

  • sudo apt install python3-pip python3-dev build-essential
  • sudo pip3 install --upgrade pip
  • sudo pip3 install django

安装mysql以及python mysqlclient

  • sudo apt install mysql-server
  • sudo apt install libmysqlclient-dev
  • sudo pip3 install mysqlclient

安装flask web框架

virtualenv 虚拟环境安装

  • sudo pip3 install virtualenv
  • virtualenv env
  • source env/bin/active

安装flask

  • pip3 install flask

离开

  • deactivate

通过uwsgi将django web项目部署到nginx服务器上

  • sudo pip3 install uwsgi

服务器配置

server{
    listen 443 ssl default_server;
    listen [::]:443 ssl default_server;
    server_name www.wh14.club;
    ssl on;
    ssl_certificate /var/www/ssl/1_www.wh14.club_bundle.crt;
    ssl_certificate_key /var/www/ssl/2_www.wh14.club.key;
    ssl_session_timeout 5m;
    ssl_protocols TLSv1.1 TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
    ssl_prefer_server_ciphers on;
    charset utf-8;
    access_log /var/www/log/access_log;
    error_log /var/www/log/error_log;
    client_max_body_size 75M;
    location /static {
        alias /var/www/static;
    }
    location /{
        uwsgi_pass 127.0.0.1:8000;
        include uwsgi_params;
    }
}
uwsgi 配置

[uwsgi]

socket = 127.0.0.1:8000
chdir = /var/www
module = www.wsgi
master = true
processes = 2
threads = 2
max-requests = 6000
chmod-socket = 664
vacuum = true
daemonize = /var/www/log/uwsgi.log
py-autoreload = 1

安装virtualenv管理工具

  • pip install virtualenvwrapper
  • export WORKON_HOME=$HOME/Envs
  • export virtualenvwrapper_python=/usr/bin/python3
  • source /usr/local/bin/virtualenvwrapper.sh
  • 新建虚拟环境 mkvirtualenv [虚拟环境名称]
  • 启动切换虚拟环境 workon [虚拟环境名称]
  • 删除虚拟环境rmvirtualenv [虚拟环境名称]、
  • 离开虚拟环境deactivate

uwsgi停止

  • sudo killall -9 uwsgi

转载于:https://my.oschina.net/skullzgr/blog/1861053

你可能感兴趣的:([学习笔记]ubuntu16.04编译安装nginx)