My first python web development framework (20)-product release (deployed on the server) and python product release

Source: Internet
Author: User
Tags psql server website svn client import database

My first python web development framework (20)-product release (deployed on the server) and python product release

First, as described in the previous chapter, after the server environment is installed, the website will be deployed to the server in steps.

Our site is separated from the front and back ends, so we need to deploy two sites. First, release the front-end site.

 

  Deploy front-end sites

Enter the command to go To the svn management Folder: cd/data/svn/

Create svn: svnadmin create simple_html

  

Go to the svn account and password management Folder: cd/data/svn/simple_html/conf/

Create a svn account: vi authz (Add the following code to the file)

[simple_html:/]py = rw

Edit svn account password: vi passwd (Add the following code to the file)

py = 123456

Modify svn configuration information: vi svnserve. conf (modify the content in the configuration file to the following parameters)

anon-access = noneauth-access = writepassword-db = passwdauthz-db = authz

Go to the hook Folder: cd/data/svn/simple_html/hooks/

Add the hook file: vi post-commit (Add the following code to automatically publish the code after svn successfully submits the code)

#!/bin/sh# POST-COMMIT HOOKexport LANG=en_US.UTF-8/usr/bin/svn up --username=py --password=123456 /data/www/simple_html

Grant executable permissions to the hooks: chmod + x post-commit (the hooks can be executed only after the executable permissions are granted)

Create a front-end website publishing Folder: mkdir/data/www/simple_html

Check out svn to the new website release Folder: svn checkout svn: // localhost/simple_html/data/www/simple_html/(enter the account created earlier: py and password 123456, enter y in the prompt Store password unencrypted (yes/no. If the svn: E000013 xxx Permission denied error occurs after running, it may be that the svn configuration you just modified has not taken effect. Restart svn)

Install an svn client on your local computer (I am using a TortoiseSVN-1.9.4.27285-x64-svn-1.9.4.msi) and check out the newly created svn to your local

  

Copy the front-end html code to the detected folder and submit it to the server.

  

Check the server website folder to see if the submitted svn is automatically released.

  

Configure nginx for normal browser access

Go to the nginx configuration Folder: cd/usr/local/nginx/conf/vhost/(if you follow the instructions in the previous section, test has been created here. conf configuration, otherwise port 80 will conflict, you can delete it: rm-rf test. conf)

Create the simple_html.conf configuration file: vi simple_html.conf (Add the following code)

server {    listen      80;    charset     utf-8;    root        /data/www/simple_html;    server_name am.zh192.168.0.128;        location /favicon.ico {                  log_not_found off;        access_log off;        }         location / {                index  Index.html index.html;        }    access_log  /data/logs/nginx/simple_html.log  main;}

Restart nginx to make the configuration take effect:/usr/local/nginx/sbin/nginx-s reload

Enter http: // 192.168.0.128/in the browser to access the front-end html page. Because the interface has not been deployed, the middle part is blank after access, press F12 to find that the interface cannot be accessed. Next, deploy the backend interface service.

  

 

  Deploy backend interface sites

The steps for creating svn are the same as the previous steps. We will create a svn named simple_interface. For details, refer to the previous section.

When creating a hook, because supervisord + uwsgi is required for the interface, you need to add the command to restart the supervisord service in the hook to make the released Code take effect again.

Vi post-commit

#!/bin/sh# POST-COMMIT HOOKexport LANG=en_US.UTF-8/usr/bin/svn up --username=py --password=123456 /data/www/simple_interface/usr/bin/supervisorctl restart simple_interface

Remember to grant the executable permission to post-commit.

After you check simple_interface to/data/www/simple_interface on the server side, the interface svn is created successfully, and then configure supervisord

Enter the command: vi/etc/supervisord. conf (the test configuration created earlier can be directly deleted here)

Add the following configuration after supervisord. conf

[program:simple_interface]command=/usr/local/bin/uwsgi /etc/uwsgi/simple_interface.inidirectory=/data/www/simple_interfacestdout_logfile=/data/logs/supervisord/simple_interface.logsocket-timeout=3autostart=trueautorestart=trueredirect_stderr=truestopsignal=QUIT

Add uwsgi configuration: vi simple_interface.ini (if the project is officially launched, it is best to use python35_plugin.so to run the xml configuration. The stability and performance will be much better. I have no experience in configuring the server environment in the early stage, so if no configuration is successful, you can only use ini)

[uwsgi]socket = 127.0.0.1:10080chdir = /data/www/simple_interface/wsgi-file = /data/www/simple_interface/main.pylimit-as = 512reload-on-as = 256reload-on-rss = 192processes = 1max-requests = 1000pythonpath = /data/www/simple_interface/daemonize = /data/logs/uwsgi/simple_interface_uwsgi.loglog-maxsize = 10000000disable-logging = truemaster = truevacuum = trueno-orphans = true

Supervisord load addition configuration (Use this command if supervisord. conf is modified):/usr/bin/supervisorctl reread

Update to process management:/usr/bin/supervisorctl update (this command will start a service with changes. If it is not effective, you can also use/usr/bin/supervisorctl reload to restart the entire service. If you only change the uwsgi configuration file, you can use/usr/bin/supervisorctl restart xxx to start the specified project)

Run ps-ef | grep uwsgi to check that the added simple_interface is running.

Configure the backend interface nginx

Create the simple_interface.conf configuration file: vi/usr/local/nginx/conf/vhost/simple_interface.conf (Add the following code)

Server {listen 20080; charset UTF-8; root/data/www/simple_interface; server_name 192.168.0.128; location/favicon. ico {log_not_found off; access_log off;} location/{include uwsgi_params; using UWSGI_PYHOME/data/www/simple_interface; uwsgi_param logs/data/www/simple_interface; using UWSGI_SCRIPT main; # Corresponds to main. py uwsgi_pass 127.0.0.1: 10080; proxy_connect_timeout 2; # nginx and backend server connection timeout (proxy connection timeout) proxy_send_timeout 4; # backend server data return time (proxy sending timeout) proxy_read_timeout 4; # response time of the backend server after successful connection (proxy receiving timeout)} access_log/data/logs/nginx/simple_interface.log main ;}

Then, submit the code to the server and check whether the/data/www/simple_interface/directory is synchronized successfully.

If there is no problem, visit: http: // 192.168.0.128: 20080/api/about/to obtain the company-introduced interface. {"msg ": "\ u67e5 \ u8be2 \ u5931 \ u8d25", "data" :{}, "state":-1} (PS: msg content is a query failure, it is Unicode encoded, you must use the webmaster tool for conversion to view Chinese characters)

This is because we have not imported the database. First, we export the local database and then import it to the server.

Open CMD and enter: cd C: \ Program Files (x86) \ PostgreSQL \ 9.6 \ bin \ (this is the address of your local PostgreSQL database installed, I installed 9.4 locally)

Then enter the command to export the data: pg_dump.exe-h localhost-U postgres-p 5432 simple_db> D:/simple_db. SQL

  

After running the command, the simple_db. SQL file is displayed in the root directory of drive D and uploaded to the/tmp/directory of the server.

Switch database account: su ipvs

Log on to postgresql: psql-U postgres

Create a database simple_db: createdb simple_db

Log out of postgresql: \ q

Switch back to the root account: su root (Press enter and enter the password)

Import database structure and data: psql simple_db </tmp/simple_db. SQL

At this time, we can access: http: // 192.168.0.128: 20080/api/about/again to see the returned company introduction, and directly access http: // 192.168.0.128 the content will still be blank. This is because we have not performed reverse proxy processing on the front-end. We also need to perform the following operations:

Edit the nginx configuration of the front-end hmtl: vi/usr/local/nginx/conf/vhost/simple_html.conf (replace it with the following configuration)

upstream myweb {    ip_hash;    server 127.0.0.1:20080 weight=1 max_fails=5 fail_timeout=5s; }server {    listen      80;    charset     utf-8;    root        /data/www/simple_html;    server_name 192.168.0.128;        location /favicon.ico {                log_not_found off;        access_log off;        }        location / {                index  Index.html index.html;        }    location ~* ^/(index|api|upload)/ {        proxy_pass                 http://myweb;        proxy_cache_key            $host$uri$is_args$args;        proxy_set_header           Host $host;         proxy_set_header           X-Real-IP $remote_addr;         proxy_set_header           X-Forwarded-For $proxy_add_x_forwarded_for;        proxy_connect_timeout      3;        proxy_send_timeout         5;        proxy_read_timeout         5;    }    access_log  /data/logs/nginx/simple_html.log  main;}

PS: a reverse proxy is added. When you access a url starting with index, api, and upload, the backend interface address is called.

Restart the nginx service to make the configuration take effect:/usr/local/nginx/sbin/nginx-s reload

 

Now you can directly access http: // 192.168.0.128 to see that the home page has data.

 

When we enter http: // 192.168.0.128/login.html to log on to the background, the verification code will display an error and cannot be displayed because the font we use does not exist on the server, the address for uploading the verification code image and modifying the verification code Toolkit

Download the package after the article. The static folder contains arial. ttf font. You also need to modify the verify_helper.py file in the common folder to: font_type = '/data/www/simple_interface/static/arial. ttf' this is to change the path of the font file uploaded for you.

As long as you are careful with the above steps, you should be able to run properly.

 

  Download the source code corresponding to this article (complete code)

 

Copyright Disclaimer: This article was originally published in the blog. The author isAllEmptyYou are welcome to repost this article, but this statement must be retained without the author's consent, and the original article connection is clearly provided on the Article Page, otherwise it is deemed as infringement.

Python development QQ group: 669058475 author blog: http://www.cnblogs.com/EmptyFS/

Related Article

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.