使用nginx
可參考此篇安裝
http://blog.hellojcc.tw/2015/12/07/nginx-beginner-tutorial/
重啟指令
sudo nginx -s stop && sudo nginx在Linux ubuntu 下的default webpage 路徑為
var/www/html或
/usr/share/nginx/htmlnginx的config 檔案路徑
會先經過 nginx.conf 之後才會去 sites-available/default
https://stackoverflow.com/a/43644053/4622645
/etc/nginx/nginx.conf
/etc/nginx/sites-available/default使用reverse proxy
location / {
proxy_pass http://localhost:3000;
}讓domain.com www.domain.com都導向https
完整範例:
設定靜態目錄
websocket有問題
加入以下配置
注意事項
設置可參考一篇不錯的文章 https://www.linode.com/docs/websites/nginx/how-to-configure-nginx#start-stop-reload
有關使用cloudflare與nginx配置之SSL可參考web_Basic之cloudflare章節
配置GZIP
https://www.digitalocean.com/community/tutorials/how-to-add-the-gzip-module-to-nginx-on-ubuntu-14-04
http://www.cnblogs.com/zfying/archive/2012/07/07/2580876.html
配置Request Limit
https://www.nginx.com/blog/rate-limiting-nginx/
EX:
記得要加上 burst (幾秒內的容許值) 與 nodelay (同時發送請求時一起執行),不然會使用平均秒數法自動幫你計算,只發兩個請求卻超過上面設置的 5r/s,產生 Nginx 503 error。
配置Load Balance
可能錯誤
1.Nginx fails to stop and nginx.pid is missing
解決方法
EXAMPLE 1: (WEB)
EXAMPLE 2: (API)
讀取index.html
記得root不可寫
~
配置優化
優化 production 部署的 server 效率
https://imququ.com/post/my-nginx-conf-for-wpo.html
注意事項
1.有時如果以下指令出現"nginx.pid" failed
可替換為
2.nginx: [emerg] open() "/usr/local/Cellar/nginx/1.15.0/logs/error.log" failed (2: No such file or directory)
可以創建一個error.log檔案即可
3.nginx: [emerg] bind() to 0.0.0.0:82 failed (13: Permission denied)
Last updated
Was this helpful?