windows下nginx+mongrel配置
学习rails也一段时间了,也做了几个小项目,在发布的时候却碰到了些小麻烦,习惯了windows的图形化操作,配置nginx的时候很是伤了翻脑筋.
1.安装mongrel:
gem install mongrel
gem install mongrel_cluster
直接解压就行了,如(C:\nginx-0.8.39)
3. 配置nginx:
我安装nginx的路径是:C:\nginx-0.8.39
打开:C:\nginx-0.8.39\nginx\conf\nginx.conf
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; upstream mongrel { server 127.0.0.1:3000; } server { listen 80; server_name localhost; charset utf-8; #access_log logs/host.access.log main; location / { root E:\xing\public; index index.html index.htm; proxy_pass http://mongrel; 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; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443; # server_name localhost; # ssl on; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_timeout 5m; # ssl_protocols SSLv2 SSLv3 TLSv1; # ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} }
4.配置mongrel:
我的项目在E:\rails目录
# mongrel_rails cluster::configure -e development -p 8000 -N 3 \
-c E:/rails -a 127.0.0.1
注:-e 指定environment。-p 端口 。 -N mongrel服务进程数
会在E:\rails\config\中生成mongrel_cluster.yml文件,文件内容为:
---
address: 127.0.0.1
log_file: log/mongrel.log
port: "3000"
cwd: E:\rails
environment: development
pid_file: tmp/pids/mongrel.pid
servers: 1
address: 127.0.0.1
log_file: log/mongrel.log
port: "3000"
cwd: E:\rails
environment: development
pid_file: tmp/pids/mongrel.pid
servers: 1
5.命令mongrel_rails cluster::start启动mongrel集群
6.启动nginx
nginx.exe -c conf\nginx.conf 结束nginx命令:taskkill /F /IM nginx.exe>nul
不出意外,打开http://localhost/应该就没问题了