首頁  >  文章  >  後端開發  >  伺服器 mac安裝nginx環境

伺服器 mac安裝nginx環境

WBOY
WBOY原創
2016-08-08 09:27:25924瀏覽

前段時間接觸到了代理伺服器,在摸索下搭建了nginx環境,接下來給大家介紹一下在mac上安裝nginx環境的基本步驟。

  1. 本文是利用homebrew來安裝nginx,先打開終端機輸入安裝命令列
    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    來安裝homebrew。官網:http://brew.sh/ 。
    若出現以下提示,表示mac已安裝nginx或上一次安裝nginx失敗留下殘餘
    It appears Homebrew is already installed. If your intent is to reinstall you
    should do the following before running this installer again:
        rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup
    按照提示輸入刪除命令列:
    rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup
    刪除後,再輸入安裝命令列。
  2. 下載homebrew後會自動安裝homebrew,用brew一鍵安裝nginx
    brew install nginx
  3. 安裝後測試nginx權限是否能正常工作
    nginx -t
    正确提示:nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
             nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
  4. 安裝後測試nginx權限權限
    chmod 777 file
    file为需要开放权限的文件路径
  5. nginx能正常運作後,先更改nginx的設定檔
    vim /usr/local/etc/nginx/nginx.conf
    server {
            listen       9999(自定义端口号);
            server_name  localhost;
    
            #charset koi8-r;
    
            #access_log  logs/host.access.log  main;
    
            location / {
                root   /Users/loki/Desktop/web/(需要部署应用的文件路径);
                index  index.html index.htm;
            }
  6. 設定檔更改完,啟動nginx
    sudo nginx
  7. 以上就介紹了伺服器 mac安裝nginx環境,包括了方面的內容,希望對PHP教學有興趣的朋友有幫助。
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn