openshift上安裝nginx反向代理(失敗記錄)

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章