Deployment with Apache

Issue #40 new
damufo
created an issue

Is possible connect weezy.web to work with apache? Any example?

Comments (8)

  1. damufo reporter

    Help to deployment apache

    Hi, I put in ...apache2/sites-enabled/000-default.conf

    <VirtualHost *:80>
            # The ServerName directive sets the request scheme, hostname and port that
            # the server uses to identify itself. This is used when creating
            # redirection URLs. In the context of virtual hosts, the ServerName
            # specifies what hostname must appear in the request's Host: header to
            # match this virtual host. For the default virtual host (this file) this
            # value is not decisive as it is used as a last resort host regardless.
            # However, you must set it for any further virtual host explicitly.
            #ServerName www.example.com
    
            ServerAdmin webmaster@localhost
            DocumentRoot /var/www/html
    
    
            WSGIDaemonProcess proba_wsgi user=proba group=proba maximum-requests=10000
            WSGIScriptAlias /proba /home/proba/probaweb/hello.py
            <Location /proba>
                    WSGIProcessGroup proba_wsgi
            </Location>
            ...
    

    hello.py has:

    """ Minimal helloworld application.
    """
    
    from wheezy.http import HTTPResponse
    from wheezy.http import WSGIApplication
    from wheezy.routing import url
    from wheezy.web.handlers import BaseHandler
    from wheezy.web.middleware import bootstrap_defaults
    from wheezy.web.middleware import path_routing_middleware_factory
    
    
    class WelcomeHandler(BaseHandler):
    
        def get(self):
            response = HTTPResponse()
            response.write('Hello World!1<br><a href="/welcome">welcome</a>')
            return response
    
    
    def welcome(request):
        response = HTTPResponse()
        response.write('Hello World!2')
        return response
    
    
    all_urls = [
        url('', WelcomeHandler, name='default'),
        url('welcome', welcome, name='welcome')
    ]
    
    
    options = {}
    main = WSGIApplication(
        middleware=[
            bootstrap_defaults(url_mapping=all_urls),
            path_routing_middleware_factory
        ],
        options=options
    )
    
    
    if __name__ == '__main__':
        from wsgiref.simple_server import make_server
        try:
            print('Visit http://localhost:80/')
            make_server('', 80, main).serve_forever()
        except KeyboardInterrupt:
            pass
        print('\nThanks!')
    

    but not work, apache report:

    Forbidden

    You don't have permission to access /proba/ on this server. Apache/2.4.10 (Debian) Server at 192.168.0.176 Port 80

    Any idea?

  2. damufo reporter

    Hi, Another test. Apache, enable site: WSGIScriptAlias /proba /home/proba/probaweb/hello.wsgi <Directory "/home/proba/probaweb"> Require all granted </Directory>

    I add file /home/proba/probaweb/hello.wsgi

    ...

    -- coding: utf-8 -*

    import os, sys

    sys.path.append('/home/proba/probaweb')

    def application(environ, start_response): from hello
    output = hello.welcome() start_response('200 OK', [('Content-Type', 'text/html; charset=utf-8')])

    return output
    

    ...

    In /home/proba/probaweb/ is also hello.py

    Now apache return 500 Internal Server Error

  3. damufo reporter

    Solved!!

    nano /etc/apache2/sites-enabled/000-default.conf

    <VirtualHost *:80>
            ServerAdmin webmaster@localhost
            DocumentRoot /var/www/html
            WSGIDaemonProcess proba user=www-data group=www-data \
             processes=2 threads=15 display-name=%{GROUP}
            WSGIProcessGroup proba
            WSGIScriptAlias /proba /home/www-data/probaweb/wsgihandler.py
            WSGIPassAuthorization On
            <Directory "/home/www-data/probaweb">
              AllowOverride None
              <Files wsgihandler.py>
                Require all granted
              </Files>
            </Directory>
    ...
    

    File /home/www-data/probaweb/wsgihandler.py

    import os
    import sys
    
    home = '/home/www-data/'
    sys.path.append(home + 'probaweb')
    os.chdir(home + 'probaweb')
    
    from hello import main
    
    def application(environ, start_response):
        environ['SCRIPT_NAME'] = ''
        return main(environ, start_response)
    

    and file /home/www-data/probaweb/hello.py

  4. Log in to comment