Python Base app---virtual host creation

Source: Internet
Author: User
Tags python script

Application Scenarios:

with python script for automating the configuration of virtual machine hosts.
Automatic configuration of two virtual hosts, domain name www.abc.com and www.python.com
and automatically generate a simple test page (test page content Customization)

# #提示这里用apache来测试, the installation is complete.

[[Email protected] pytonjiaoben]# cat a.py#-*- coding:utf-8 -*-import osdef  peizhi ():   try:     f=open ("/etc/httpd/conf.d/a.conf", "W")       os.system ("echo python > /var/www/index.html")       os.system ("echo abc > /var/www/html/index.html")       F.write ("' listen 8080<virtualhost *:8080>         documentroot  "/var/www"         ServerName www.python.com< /virtualhost><virtualhost *:80>        documentroot   "/var/www/html"         servername www.abc.com</ virtualhost>  ')   except ioerror:     os.system ("mkdir - P /etc/httpd/conf.d/a.conf ")      f=open ("/etc/httpd/conf.d/a.conf", "W")      f.write ("Listen  8080<VirtualHost *:8080>        DocumentRoot  "/ Var/www "        ServerName www.python.com</VirtualHost>< virtualhost *:80>        documentroot  "/var/www/html"         ServerName www.abc.com</VirtualHost>   " ) Def ceshi ():   peizhi ()   os.system ("Service httpd restart")     print  "------------web1-----------"   os.system ("curl www.python.com:8080 ")   print  "------------web2-----------"   os.system ("curl www.abc.com") Ceshi ()

now let's take a look at the results of the execution :

[[email protected] pytonjiaoben]# python a.py stop httpd: [OK] starting httpd: [OK]------------web1-----------python------------web2-----------ABC

Let's test whether the virtual host we wrote will be able to access it successfully, because it is the domain name access, so we need to configure the local domain name resolution:

To view ports:

[[email protected] pytonjiaoben]# netstat -ntplactive internet connections  (only servers) proto recv-q send-q local address                Foreign Address              State       PID/Program name    tcp        0      0 0.0.0.0:111                  0.0.0.0: *                    LISTEN      2005/rpcbind         Tcp        0      0 0.0.0.0:22                   0.0.0.0: *                    LISTEN      2328/sshd            tcp        0      0  127.0.0.1:631                0.0.0.0:*                    LISTEN      2182/cupsd           tcp        0       0 0.0.0.0:44484                0.0.0.0:*                   LISTEN       2148/rpc.statd      tcp         0      0 0.0.0.0:3306                 0.0.0.0:*                    LISTEN       67460/mysqld        tcp         0      0 :::48779                     :::*                           listen      2148/rpc.statd      tcp         0      0 :::111                       :::*                           LISTEN      2005/rpcbind         tcp        0       0 :::8080                      :::*                          LISTEN       77172/httpd         tcp        0       0 :::80                        :::*                           Listen      77172/httpd         tcp         0      0 :::22                         :::*                          listen      2328/ sshd           tcp        0       0 ::1:631                      :::*                          LISTEN       2182/

You can see that the port has been up and visited to see:

[[email protected] pytonjiaoben]# Curl Www.python.com:8080python[[email protected] pytonjiaoben]# Curl WWW.ABC.COMABC

# #访问成功;


Summary: We found that the deployment of virtual hosts based on Python is quite easy to implement.

This article is from the "My Operations" blog, so be sure to keep this source http://xiaozhagn.blog.51cto.com/13264135/1982601

Python Base app---virtual host creation

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.