Flask+nginx+gunicorn+github+ubuntu deployed to Baidu Cloud

Source: Internet
Author: User
Tags virtual environment virtualenv

Deployment based on ubuntu/16.04 LTS AMD64 (64bit)

Shh Root Login

1. Installing python,pip,virtualenv

In general, Ubuntu has its own python. Python's package management tool has 2 (EASY_INSTALL,PIP), the former is the previous one, the latter is used more.

Install pip
Apt-get Install Virtualenv

2. Create a file directory that you can use to upload items from git.

1. Install Gitapt-get installation git2. Create a new user to deploy code using, unprivileged useradd-m Mavis passwd xxx3. Create a new deployment directory mkdir/var/www/ Myflask4. Change the owner and owner group of the deployment directory to user Maviscd/var/www/chown Mavis:mavis myflask5. Switch User su Mavis (want to switch back to root, direct SU enter + Enter your password) 6. Initialize CD myflaskgit init for Myflask (if unsuccessful, try git init--bare) 7. Let the warehouse accept the code commit git config receive.denycurrentbranch Ignore the address of this warehouse is    ssh://[email Protected]/var/www/myflask/.git local Warehouse Preparation: 1. Open your GitHub, click Commit to Master, That is, submit to local warehouse 2. In the top-most repository on GitHub, select Open in Terminal3. Then enter git remote add resume Ssh://[email protected]/var/www/myflask/. GIT4. Commit to server git push resume masterresume This your own random name, just used to differentiate between different servers back to server 1. Update the server side Cd/var/www/myflaskgit Update-server-infogit Checkout-f2. See if the file is updated. 3. Set the server-side update Hook CD. Git/hookstouch Post-receivevim post-receive  The following content is written   #!/bin/sh   unset git_dir   cd   . Git checkout-f          

  

3. Installing Nginx

1. First install the NGINXAPT-getInstallNginx2. Then go to configure the service file first back up the good habits and then openCP/etc/nginx/sites-available/default/etc/nginx/sites-available/Default.bakvim/etc/nginx/sites-available/default server {Listen the; server_name mavisnclara.com; # This is the external domain name of the host machine, with the address also line location/{proxy_pass http://127.0.0.1:8080. # Here is the service address to Gunicorn hostProxy_set_header Host $host; Proxy_set_header X-forwarded-For $proxy _add_x_forwarded_for; }} exit after saving3The service Nginx Restart must be restarted after modification.

4. Start virtualenv and install Gunicorn run

cd/var/www/myflask# Create a new virtual environment virtualenv venv# start the virtual environment source Venv/bin/activate# If you need to exit: deactivate# Installing GUNICORNAPT install gunicorn# in a virtual environment flaskapt install127.0 . 0.1:8080 Mavischen:app

Enter your IP address in the browser to access

Flask+nginx+gunicorn+github+ubuntu deployed to Baidu Cloud

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.