1、在本地安装openshift rhc(Rails集成ruby)

2、在openshift注册账号,记录下ssh

3、进入本地"Command Prompt with Ruby and Rails"

rhc app create mysite diy-0.1
rhc app show -a mysite

4、使用putty,ssh连接mysite(ssh @mysite.rhcloud.com)

5、安装nginx和pcre插件

cd $OPENSHIFT_TMP_DIR
wget http://nginx.org/download/nginx-1.2.2.tar.gz #下载参考Nginx官网
tar zxf nginx-1.2.2.tar.gz
wget 
tar jxf pcre-8.36.tar.bz2 
cd nginx-1.2.2
./configure --prefix=$OPENSHIFT_DATA_DIR --with-pcre=$OPENSHIFT_TMP_DIR/pcre-8.36

如果你能看到一下文字,说明配置正常,然后可以继续执行.
Configuration summary
+ using PCRE library: /tmp//pcre-8.31
+ OpenSSL library is not used
+ md5: using system crypto library
+ sha1: using system crypto library
+ using system zlib librarynginx path prefix: "/var/lib/stickshift/c45cdc9a27944dc5b1cd7cb9e5c9f8c7/mysite/runtime/"
nginx file: "/var/lib/stickshift/c45cdc9a27944dc5b1cd7cb9e5c9f8c7/mysite/runtime//sbin/nginx"
nginx configuration prefix: "/var/lib/stickshift/c45cdc9a27944dc5b1cd7cb9e5c9f8c7/mysite/runtime//conf"
nginx configuration file: "/var/lib/stickshift/c45cdc9a27944dc5b1cd7cb9e5c9f8c7/mysite/runtime//conf/nginx.conf"
nginx pid file: "/var/lib/stickshift/c45cdc9a27944dc5b1cd7cb9e5c9f8c7/mysite/runtime//logs/nginx.pid"
nginx error log file: "/var/lib/stickshift/c45cdc9a27944dc5b1cd7cb9e5c9f8c7/mysite/runtime//logs/error.log"
nginx http access log file: "/var/lib/stickshift/c45cdc9a27944dc5b1cd7cb9e5c9f8c7/mysite/runtime//logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"

make install (时间较长,ssh会断,不知道make install& 命令可以不)

vi $OPENSHIFT_DATA_DIR/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;

upstraem name{
 server ip:80 max_files=3;
 server ip:80 max_files=3;
 server ip:80 max_files=3;
 server ip:80 max_files=3;
 server ip:80 max_files=3;
 server ip:80 max_files=3;
 }
server {
listen OPENSHIFT_IP:$OPENSHIFT_PORT;//在app启动时,用.openshift/action_hooks/start中,执行命令,用openshift中env中,环境变量中的IP和PORT变量替换
server_name localhost;
location / {
proxy_redirect http://www.googlecom/;
proxy_cookie_domain.com mystie.rhcloud.com;//这里请替换成你的域名
proxy_pass  upstream name;
proxy_set_header Accept-Encoding “”;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
}
}
}
保存这个文件后需要执行
mv $OPENSHIFT_DATA_DIR/conf/nginx.conf $OPENSHIFT_DATA_DIR/conf/nginx.conf.template这一步很重要,如果不执行则无法保存

git clone  ssh://[email protected]/~/git/nginx.git/
本地c盘会多一个site文件夹
进入本地"Command Prompt with Ruby and Rails"
rhc setup
cd mysite(nginx)

vi .openshift/action_hooks/start

#!/bin/bash
# The logic to start up your application should be put in this
# script. The application will work only if it binds to
# $OPENSHIFT_INTERNAL_IP:8080
# nohup $OPENSHIFT_REPO_DIR/diy/testrubyserver.rb $OPENSHIFT_INTERNAL_IP
 $OPENSHIFT_REPO_DIR/diy > $OPENSHIFT_DIY_LOG_DIR/server.log 
2>&1 &
# replace the $OPENSHIFT_INTERNAL_IP and $OPENSHIFT_INTERNAL_PORT before starting up the server
sed -e "s/`echo '$OPENSHIFT_IP:$OPENSHIFT_PORT'`/`echo $OPENSHIFT_DIY_IP:$OPENSHIFT_DIY_PORT`/" $OPENSHIFT_DATA_DIR/conf/nginx.conf.template > $OPENSHIFT_DATA_DIR/conf/nginx.conf
nohup $OPENSHIFT_DATA_DIR/sbin/nginx > $OPENSHIFT_DIY_LOG_DIR/server.log 2>&1 &
最后发送命令
git commit -a -m "start nginx when starting up the app"
git push
嗯..这样就配置完了.
如果你在配置过程中有任何问题可以执行rhc tail -a mysite查看Log

参考:

1、openshift安装Nginx并 反向代理 Google

2、Nginx反向绑定域名方法和详细操作应用实例:Google和Gravatar

3、Running Nginx on OpenShift

4、Nginx, PHP5.5 and Phalcon on OpenShift

5、Install Nginx in OpenShift

6、git clone