Good day fellow CherryPyers,
I am learning to use CherryPy and making good progress, but I have hit a roadblock.
I am following the tutorials in the documentation, but I am using Nginx as a reverse-proxy to the CherryPy server.
I am not sure if I explained my problem well in the title. I am making an extremely simple website just to test the set-up, but I cannot get it to work correctly. I can successfully display a single application, but I cannot figure out how to host different applications at different URLs. I am getting this error:
TypeError: object of type 'website' has no len()I am sure I am missing very simple but I cannot, for the life of me, figure it out.
These are the files in my root directory:
=========================
application_module.py=========================
import cherrypy
class website(object):
@cherrypy.expose
def index(self):
return ("The cute bunny hopped through the forest.")
@cherrypy.expose
def brown(self):
return ("The brown bunny has very good luck.")
=========================
wsgi.py=========================
import application_module
def application(env, start_response):
start_response('200 OK', [('Content-Type', 'text/html')])
return [application_module.website()]
=========================
server.py=========================
from wsgi import application
import cherrypy
if __name__ == '__main__':
cherrypy.tree.graft(application, "/")
cherrypy.server.unsubscribe()
server = cherrypy._cpserver.Server()
server.socket_host = "0.0.0.0"
server.socket_port = 8080
server.thread_pool = 30
server.subscribe()
cherrypy.engine.start()
cherrypy.engine.block()
=========================
and this is the Nginx configuration file:=========================
worker_processes 1;
events {
worker_connections 1024;
}
http {
sendfile on;
gzip_http_version 1.0;
gzip_proxied any;
gzip_min_length 500;
gzip_disable "MSIE [1-6]\.";
gzip_types text/plain text/xml text/css
text/javascript
application/javascript;
upstream apps {
server 127.0.0.1:8080;
server 127.0.0.1:8081;
}
server {
listen 80;
# server_name www.example.com
server_name localhost;
# access_log /app/logs/www.example.com.log combined;
# error_log /app/logs/www.example.com.log;
location ^~ /static/ {
root /home/user/cherrypy_website/static;
}
location / {
proxy_pass http://apps;
proxy_redirect off;
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_set_header X-Forwarded-Host $server_name;
}
}
}