我的windows環境:Win7 64位
OpenShift百度百科 調戲OpenShift:一個免費能干的云平臺
按照該教程,安裝完畢后,再進行rhc setup設置時,輸入openshift賬戶密碼后,一直沒有反應,后來找了官網上的教程,進行的安裝; 1、意思是先安裝Git for Windows 2、安裝Ruby 3、安裝rhc,安裝成功后,截圖如下,與教程里稍有不同。 
新版OpenShift空間文件目錄結構
OpenShift空間文件系統結構說明如下:
|– .env??#空間環境配置
|– app-root??#應用目錄
|?? |– data??#存儲數據
|?? |– repo -> runtime/repo?? #代碼
這里要提醒一下,當你創建應用時你的代碼就會被放在app-root下的repo下面,你的應用本身產生的數據是存儲在app-root下的data下面的 
app-root目錄是你的應用運行時代碼所在的目錄 app-deployments是你git把代碼提交上去后git遠程庫的目錄,也就是部署上去的目錄
1、廖雪峰的Git教程:教程比較詳細,初學者可以參考 2、最新Openshift搭建 - 貼吧云簽到圖文教程:介紹了如何利用openshift搭建了百度貼吧簽到系統。 3、Getting Started with Python 2.6, 2.7, and 3.3:官方文檔 4、Python Web 應用:WSGI基礎 5、python學習:最簡單的web應用(WSGI接口):下面是具體介紹 web應用本質上來說就是: 瀏覽器發送一個HTTP請求; 服務器收到請求,生成一個HTML文檔; 服務器把HTML文檔作為HTTP響應的Body發送給瀏覽器; 瀏覽器收到HTTP響應,從HTTP Body取出HTML文檔并顯示。 [0]我們要生成一個動態的web應用.如果由自己來寫底層代碼就太麻煩了.所以python提供了一個統一的接口,讓我m只需要處理瀏覽器的請求,而不用去管各種協議.這個接口就是WGSI. 下面的代碼就是利用wsgiref模塊創建一個服務器,監聽瀏覽器的請求,并且作出回應.
from wsgiref.simple_server import make_server# 自己編寫的application函數:def application(environ, start_response): start_response('200 OK', [('Content-Type', 'text/html')]) body = r'<h1>Hello, %s!</h1>'%(environ['PATH_INFO'][1:] or 'web') return [body.encode('utf-8')]# 創建一個服務器,ip地址為空,端口是8000,處理函數是application:httpd = make_server('127.0.0.1', 8000, application)print('Serving HTTP on port 8000...')# 開始監聽HTTP請求:httpd.serve_forever()wsgi接受一個處理函數,這個處理函數接受兩個參數:一個是HTTP響應碼,一個是一組list表示的HTTP Header,每個Header用一個包含兩個str的tuple表示。HTTP請求的所有輸入信息都可以通過environ獲得,HTTP響應的輸出都可以通過start_response()加上函數返回值作為Body。 6、web python – WSGI接口:另外一個寫wsgi.py的例子
#! /usr/bin/env python# Our tutorial's WSGI serverfrom wsgiref.simple_server import make_serverdef application(environ, start_response): # Sorting and stringifying the environment key, value pairs response_body = ['%s: %s' % (key, value) for key, value in sorted(environ.items())] response_body = '/n'.join(response_body) status = '200 OK' response_headers = [('Content-Type', 'text/plain'), ('Content-Length', str(len(response_body)))] start_response(status, response_headers) return [response_body]# Instantiate the WSGI server.# It will receive the request, pass it to the application# and send the application's response to the clienthttpd = make_server( 'localhost', # The host name. 8051, # A port number where to wait for the request. application # Our application object name, in this case a function. )# Wait for a single request, serve it and quit.httpd.handle_request()事先準備好軟件:winscp,puttygen
1、在openshift建立好新的應用; 2、按《參考教程-2》例程所示,在puttygen軟件上生成密匙,公匙,并連接好。 3、打開本地winscp程序,下圖右邊Source Code里的代碼復制過來,其中從ssh://后面到/~/git/python.git/之間的內容,作為主機名填入winscp,點擊’高級’,導入密匙(《參考教程-2》中有詳細步驟) 
連接到openshift后,winscp右側顯示如下,為新建程序在服務器上的文件夾目錄 
4、進入app-root/runtime/repo文件夾,會發現文件夾下有如下幾個文件 
.openshift:這個文件夾及其中內容不需要操作 requirements.txt:可添加需要的依賴庫(默認為空) setup.py:添加一些配置信息(也可以添加依賴庫) wsgi.py:python應用默認的入口文件
我們可以通過修改wsgi.py里面的代碼,來修改主頁內容 5、將wsgi.py里面標簽下內容改成hello,保存后,打開openshift上程序,則在主頁上就顯示出hello字樣 以下是官網文檔,意思差不多
To make the first change, edit wsgi.py in the base of the local git repository. Go to the file in the terminal and edit with a command line editor like VIM or EMacs. Alternatively, edit the file using any text editor or IDE. The beginning of this file starts a basic WSGI application with some URL routing. Strip out everything between the two < body> tags and change the content to look like this:
<body> <h1>Hello world!</h1></body>6、將wsgi.py再次重寫:
1、node.js介紹 2、如何基于OpenShift進行微信公眾號開發 3、openshift之Python生成在線API:里面有介紹如何在openshift上安裝運行python程序 4、Flask——使用Python和OpenShift進行即時Web開發
新聞熱點
疑難解答