跳到主要內容

發表文章

目前顯示的是有「nginx」標籤的文章

nginx config path for mac envorinment

nginx for mac envorinment if you are a mac user and have to process nginx config for your local env, there is path and url for you there is a note for myself. /usr/local/etc/nginx/nginx.conf nginx cli start server sudo nginx restart server sudo nginx -s reload stop server sudo nginx stop

nginx call php and node.js by route forward

sudo apt-get install php5-fpm sudo vim /etc/php5/fpm/php.ini cgi.fix_pathinfo=0 safe_mode = Off restart php fpm sudo service php5-fpm restart generate php file path mkdir /usr/share/nginx/www vim $CKFINDER/config.php 修改檔案位置,以及網址設定 $baseUrl = 'http://domain.com/path/'; $baseDir = '/PATH/FOLDER/IMAGES'; i have no idea, why there is images floder more. but, it works chmod 777 $FOLDER_PATH edit nginx server { listen 80; root /usr/share/nginx/www; location ~ \.php$ { try_files $uri =404; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } location / { proxy_set_header X-Real-IP $remote_addr; proxy_pass http://127.0.0.1:1337; proxy_set_header X-Forwarded-For $remote_addr; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; p...

[教學] 快快樂樂申請 ssl 憑證 certificate signed by a CA for your domain

certificate signed by a CA for your domain mac brew install openssl ubuntu apt-get install opensll 當 opensll 安裝好之後,就可以開始建立 key, csr 簽署檔案。 mkdir /etc/ssl/localcerts cd /etc/ssl/localcerts openssl req -new -newkey rsa:2048 -nodes -sha256 -days 365 -keyout www.mydomain.com.key -out www.mydomain.com.csr 注意: 要特別注意檔案名稱,通常會建議命名為 domain name 之後會比較容易識別,但不是一定要。 e.g. www.caesarchi.com -> www.caesarchi.com.csr 「重要」,在輸入 Common Name (CN) 的時候,記得輸入 domain name。 e.g. Common Name (e.g. server FQDN or YOUR name) []:www.caesarchi.com chmod 400 /etc/ssl/localcerts/www.mydomain.com.key 如果是透過線上申請 RapidSSL , 將 csr 的資料填入,填寫完畢後,會將 crt 所需要的檔案透過 email 送到信箱中。 需要將 xxx.xxx.csr 檔案內容複製,貼上到申請表格中,讓服務商可以產生出來憑證。 將 Intermediate 和 SSL 合成 當取得 crt 檔案之後,會發現有兩筆 crt 分別為 server.crt Intermediate.crt 請將 server.crt 複製到 server 上,並且透過指令將 intermedia.crt 檔案兩者合併。 cat intermediate.crt >> SSL.crt 組合之後,目前簽證也算是告一個段落。但是 crt 檔案,記得將權限修改一下 chmod 400 SSL.crt 將 ssl 設定到 nginx 在原有的 nginx 設定裡面,將剛才 ss...

[教學] 安裝 Nginx, PHP, MySQL 在 MacOS 使用 homebrew

上次有提到在 Mac 裡面如何 安裝 Apache 以及其他相關 Web 服務 ,當然 Xampp 已經有提供這樣的完整的服務,可以讓開發者快速的建立 AMP 的環境。 本篇將介紹如何使用 homebrew 安裝 Nginx, PHP, MySQL. prepare installed homebrew install script 這邊使用的是從 github 上面找來的安裝腳本,如果有興趣知道裡面到底寫什麼的朋友,就麻煩自己下去 Google. 但是在執行 homebrew 之前,建議還是先 update 一下. sudo brew update https://gist.github.com/mystix/3041577 Setting 重新設定 MySQL root 密碼 /usr/local/opt/mysql/bin/mysqladmin -u root password 'new-password' mysql -u root -p 設定 nginx,目前預設都是 8080, 可以透過修改 nginx.conf 修改 port /usr/local/etc/nginx/nginx.conf 同時在 nginx.conf 裡面的設定解除註解,fastcgi_param 後面的數值也稍微修改一下, location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME /usr/local/var/www/$fastcgi_script_name; } 重新啟動 nginx, sudo nginx -s reload 或者關掉重新啟動 sudo nginx -s stop sudo nginx 以上步驟安裝完成,恭喜各位,接下來可以進入測試階段 try 到 html ...

[分享] XMLHttpRequest執行AJAX 跨網域存取

跟大家在介紹 Socket.io 的時候,意外發現居然Socket.io 可以執行跨網域的存取,為什麼?這個時候問題就已經埋下,挖掘之後發現!居然是平凡無奇的XMLHttpRequest,還有針對IE做的奇怪處理,到底是怎麼辦到的? 分析 W3C 提案 Cross-Origin Resource Sharing (CORS),這份文件裡面提到,可以透過文件Header 設定可存取網域限制,以及存取方法、時間等,限制的部份有幾個: 必須為http, https 傳送資料方式為GET, POST 資料格式為application/xml 透過剛才的 CORS ,發展出更高層級XMLHttpRequest,W3C裡面也有實現方式 XMLHttpRequest Level 2 草案,裡面的這一段介紹: The XMLHttpRequest Level 2 specification enhances the XMLHttpRequest object with new features, such as cross-origin requests, progress events, and the handling of byte streams for both sending and receiving. XMLHttpRequest Level 2,可以支援cross-domain 請求,這個部份符合我們的需求。與CORS結合之後,似乎就可以ajax 跨網域存取,感覺不賴。 IE呢? IE8以上有類似XMLHttpRequest Level 2的物件,稱為 XDomainRequest ,在 XDomainRequest - Restrictions, Limitations and Workarounds 這篇文章裡面仔細描述如何搭配CORS原則完成跨網域的實做。

[教學] nginx 設定 virtual host.

很多時候會用到不同子域名(sub domain),這邊講解如何使用nginx 設定不同網域名稱及設定成不同資料夾。 設定 DNS server 設定好名稱之後,修改檔案default sudo vim /etc/nginx/sites-available/default 假設目前要增加nodejs.clonn.info,資料夾為/usr/share/nginx/www/nodejs # 其他設定資料 server { listen 80; server_name nodejs.clonn.info ; root /usr/share/nginx/www/nodejs ; index index.html index.htm index.php; location / { try_files $uri $uri/ /index.html; } } # 其他設定資料 實測 在/usr/share/nginx/www,/usr/share/nginx/www/nodejs各增加不同的index.html,測試一下結果,的確如我們所想像。 結語 目前測試起來nginx和apache的設定方式雖然不大相同,不過能做到的功能大多可及,想要嘗試看看nginx的人可以一起來測試看看,另外歡迎加入 NodeJS 的行列。

[教學] nodeJS直接module加載於windows native node

NodeJS 終於在0.5.1(unstable) 版本提供了Windows native supprot.,但是美中不足的部份就是childprocess的功能支援不完全,因此無法透過node.exe來 安裝npm 。 這樣子會造成很多遺憾,例如socket.io, redis, mysql等其他外掛模組都無法加載進來,本篇文章就是講解如何直接將這些外部module加載進來,不需要經過npm或者其他腳本語言安裝module。 設定環境變數 下載node v0.5.2 native windows 將node.exe放置到自己的資料夾中(這邊預設為 c:\node )

[教學] nginx 設定 proxy server 用於node.js app. Set ngnix proxy server.

最近使用NodeJS開發程式,但是每次的網域都非常的醜,要使用xxx.xxx.xxx:8000,後面一定都要加上port號,以下解說如何在nginx 底下設定proxy 。 環境: Ubuntu server 11.04 Nodejs 0.4.0 nginx PS. 假設大家都已經學會 如何使用Node.js ,以及設 定Nginx,操作linux 。

[筆記] ubuntu 11.4 安裝nginx, php. Install nginx, php on ubuntu server 11.4

環境提要: VM OS: ubuntu server 11.4 LTS, 不同版本ubuntu server,nginx 的設置不同,因此請先確認自己的伺服器版本是否相符合! 安裝nginx sudo apt-get install nginx php5-fpm 執行nginx sudo /etc/init.d/nginx start 沒意外的話,就會出現上圖。