Can I run two web servers on the same computer?

后端 未结 7 967
执笔经年
执笔经年 2020-12-23 22:12

I just found out that I can write a really simple web server using Python. I have already an Apache web server I would like to try the Python based web server on this machi

7条回答
  •  时光说笑
    2020-12-23 22:27

    If you actually want to run separate servers to test out server software see the other answers, but...

    It sounds like (because you are a developer, not a sysadmin right?) you really just want to run Python and PHP sites on the same computer. So, forgive me if I'm reading into your question, but this setup allows me to run both kinds of sites on the same computer with the same port (port 80) in one server, Apache.

    I make new entries in my /etc/hosts file (or C:\Windows\System32\drivers\etc\hosts on Windows) and point them to 127.0.0.1:

    127.0.0.1      localhost
    
    # development projects
    127.0.0.1      somephpsite.com.local
    127.0.0.1      www.somephpsite.com.local
    127.0.0.1      otherpythonsite.com.local
    127.0.0.1      www.otherpythonsite.com.local
    

    Then in Apache I add VirtualHosts for each site:

    
        DocumentRoot "/Library/WebServer/Documents"
        ServerName localhost
    
    
    
        
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            Allow from all
        
        DocumentRoot "/Users/Robert/Projects/SomeSite/somephpsite.com"
        ServerName somephpsite.com.local
        ServerAlias www.somephpsite.com.local
        ErrorLog "/Users/Robert/Projects/SomeSite/error.log"
        CustomLog "/Users/Robert/Projects/SomeSite/access.log" common
    
    
    
        
            Order allow,deny
            Allow from all
        
        DocumentRoot "/Users/Robert/Projects/OtherSite/otherpythonsite.com/static"
        Alias /(.*(\.css|\.gif|\.ico|\.jpg|\.js|\.pdf|\.txt)) /Users/Robert/Projects/OtherSite/otherpythonsite.com/static/$1
        WSGIScriptAlias / /Users/Robert/Projects/OtherSite/otherpythonsite.com/wsgi.py
        ServerName otherpythonsite.com.local
        ServerAlias www.otherpythonsite.com.local
        ErrorLog "/Users/Robert/Projects/OtherSite/error.log"
        CustomLog "/Users/Robert/Projects/OtherSite/access.log" common
    
    

    So, the PHP sites run in the DocumentRoot like they always do. And the Python sites run in WSGI. And they both run in Apache. Then to test, I just add ".local" in whatever browser I'm using to work on my local copy.

提交回复
热议问题