macOS 10 Install Nginx - IT 484

macOS 10 Install Nginx – IT 484

  • Post author:
  • Post category:IT / Nginx
  • Post comments:0 Comments
  • Post last modified:2023-01-13

相較於其它的 Web Server ,安裝非常簡單,可以大幅地節省工程師開發與部署的時間,實作架設 Server,可以使用 Homebrew 來達成,這是最快速的方法。

功能簡介

Nginx 是一個異步框架的網頁伺服器,用於處理併發請求,整體是採用模組化設計,組態檔案也非常簡潔容易設定,同時也提供了反向代理、負載平衡器、HTTP 快取等功能,相較於 Apache、lighttpd 具有占有內存少,穩定性高等優勢,能保持低資源低消耗高性能,在網際網路項目中廣泛應用。

安裝套件

macos 10 install nginx

使用 brew 命令安裝。

brew install nginx

組態設定

這是主要的組態檔,參考此檔案的內容,視需求而調整設定。

worker_processes # 執行緒數量
events.worker_connections # 連線數
http.include # 引用其他組態檔

vim /opt/homebrew/etc/nginx/nginx.conf  
#user  nobody;
worker_processes  auto;
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;
    include servers/*.conf;
}

運行管理

啟動服務

安裝完成後,並不會自動啟動服務,使用 brew services start 命令來啟動服務。
brew services start nginx

停止服務

啟動服務後,使用 brew services stop 命令終止服務運行。

brew services stop nginx

狀態驗證

Install Nginx macOS 啟動服務後,使用 brew services info 命令來啟查看服務狀況。

brew services info nginx
nginx (homebrew.mxcl.nginx)
Running: v
Loaded: v
Schedulable: x
User: admin
PID: 810

心得分享

macOS Install Nginx 快速安裝後,便於個人電腦、筆電在開發研究或測試時使用,省略複雜的設定,所以沒有參數需要調整,簡單快速建置就能使用服務,除此之外還有其他平台:

發佈留言