I currently have one Pylons website running on my server that is setup using nginx as a proxy to Paster. In the near future, I plan to host another Pylons site on the same server.
If I were to go the same route and use nginx+Paster, it would mean running two paster instances on different ports and then usi开发者_如何学Gong the one nginx server as a proxy forwarder to 127.0.0.1:808(1|2).
It seems like a bad idea to have two paster servers running for two different sites. If I were to have 10 Pylons sites on the server, it would mean 10 Paster server instances running...
What's a better solution?
I think there is nothing wrong with running few paster instances, but you should consider using FastCGI (or wsgi) and Virtual Hosts, because it's more suitable for "production environment". Example with FastCGI:
pid /var/run/nginx.pid;
user www;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include /etc/mime.types;
default_type application/octet-stream;
sendfile on;
gzip on;
keepalive_timeout 65;
# First site
server {
listen *:443;
server_name first.example.com;
ssl on;
ssl_certificate /etc/www/cert.pem;
ssl_certificate_key /etc/www/key.pem;
ssl_session_timeout 5m;
ssl_protocols SSLv3 TLSv1;
location / {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param HTTPS on;
fastcgi_pass_header Authorization;
fastcgi_intercept_errors off;
}
access_log /var/log/first.access.log main;
error_log /var/log/first.error.log;
}
# Second site
server {
listen *:443;
server_name second.example.com;
ssl on;
ssl_certificate /etc/www/cert1.pem;
ssl_certificate_key /etc/www/key1.pem;
ssl_session_timeout 5m;
ssl_protocols SSLv3 TLSv1;
location / {
fastcgi_pass 127.0.0.1:9001;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param HTTPS on;
fastcgi_pass_header Authorization;
fastcgi_intercept_errors off;
}
access_log /var/log/second.access.log main;
error_log /var/log/second.error.log;
}
}
Now, you have to sites:
first.example.com -> localhost:9000
second.example.com -> localhost:9001
You can also set IP in for "listen", e.g.:
listen 192.168.1.1:443;
listen 192.168.1.2:443;
so you are able to use IP instead of DNS name.
For Pylons app you should change configuration to FastCGI:
[server:main]
use = egg:Flup#fcgi_thread
host = 127.0.0.1
port = 9000
for first host, and for second:
[server:main]
use = egg:Flup#fcgi_thread
host = 127.0.0.1
port = 9001
Hope this helps.
You can use a single paster instance to launch multiple applications. The link below has a nice article explaining how to use paster's urlmap to achieve this.
http://countergram.com/pylons-virtual-host-multiple-domain
精彩评论