美文网首页
mac上nginx搭建

mac上nginx搭建

作者: miky_zheng | 来源:发表于2019-02-09 15:17 被阅读0次

    1.安装Homebrew
    2.安装ngnix。终端输入:brew install ngnix报错

    Error: No available formula with the name "ngnix" 
    ==> Searching for a previously deleted formula (in the last month)...
    Warning: homebrew/core is shallow clone. To get complete history run:
      git -C "$(brew --repo homebrew/core)" fetch --unshallow
    
    Error: No previously deleted formula found.
    ==> Searching for similarly named formulae...
    Error: No similarly named formulae found.
    ==> Searching taps...
    ==> Searching taps on GitHub...
    Error: No formulae found in taps.
    

    问题:没有tap
    解决方案如下:

    //终端输入
    brew tap denji/nginx
    

    4.安装上传模块
    终端输入 brew install nginx-full --with-upload-module 报错

    Error: The following directories are not writable by your user:
    /usr/local/share/info
    
    You should change the ownership of these directories to your user.
      sudo chown -R $(whoami) /usr/local/share/info
    

    解决方案如下:

    //xxx填写你的Mac用户姓名
    sudo chown -R xxx /usr/local/share/info
    

    5.终端输入:nginx,报错

    -bash: nginx: command not found
    

    再次运行 “brew install ngnix”

    nginx: stable 1.15.8 (bottled), HEAD
    HTTP(S) server and reverse proxy, and IMAP/POP3 proxy server
    https://nginx.org/
    Not installed
    From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/nginx.rb
    ==> Dependencies
    Required: openssl ✘, pcre ✔
    ==> Options
    --HEAD
        Install HEAD version
    ==> Caveats
    Docroot is: /usr/local/var/www
    
    The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
    nginx can run without sudo.
    
    nginx will load all files in /usr/local/etc/nginx/servers/.
    
    To have launchd start nginx now and restart at login:
      brew services start nginx
    Or, if you don't want/need a background service you can just run:
      nginx
    ==> Analytics
    install: 27,568 (30 days), 99,193 (90 days), 440,662 (365 days)
    install_on_request: 26,223 (30 days), 92,425 (90 days), 395,247 (365 days)
    build_error: 0 (30 days)
    

    问题:openssl未安装

    6.继续执行“brew install openssl”报错,

    Error: openssl 1.0.2o_1 is already installed
    To upgrade to 1.0.2q, run `brew upgrade openssl`
    

    运行brew upgrade openssl解决

    7.执行 brew upgrade openssl 又会更新python,如下:

    ==> python
    Python has been installed as
      /usr/local/bin/python3
    
    Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
    `python3`, `python3-config`, `pip3` etc., respectively, have been installed into
      /usr/local/opt/python/libexec/bin
    
    If you need Homebrew's Python 2.7 run
      brew install python@2
    
    You can install Python packages with
      pip3 install <package>
    They will install into the site-package directory
      /usr/local/lib/python3.7/site-packages
    
    See: https://docs.brew.sh/Homebrew-and-Python
    

    8.再次执行 “brew install nginx”显示如下:

    ==> Downloading https://homebrew.bintray.com/bottles/nginx-1.15.8.high_sierra.bo
    ######################################################################## 100.0%
    ==> Pouring nginx-1.15.8.high_sierra.bottle.1.tar.gz
    ==> Caveats
    Docroot is: /usr/local/var/www
    
    The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
    nginx can run without sudo.
    
    nginx will load all files in /usr/local/etc/nginx/servers/.
    
    To have launchd start nginx now and restart at login:
      brew services start nginx
    Or, if you don't want/need a background service you can just run:
      nginx
    ==> Summary
    🍺  /usr/local/Cellar/nginx/1.15.8: 23 files, 1.4MB
    

    9.执行 “ngnix”,无报错。
    10.在浏览器中输入“http://localhost:8080
    网页显示“It works!”,证明nginx搭建成功。

    注:
    修改目录以及端口号:
    修改配置文件:/usr/local/etc/nginx/nginx.conf

        server {
            listen       9100;
            server_name  localhost;
    
            #charset koi8-r;
    
            #access_log  logs/host.access.log  main;
    
            location / {
                root   /Users/XXX/nginxServer;
                index  index.html index.htm;
            }
    

    重启服务sudo nginx -s reload

    相关文章

      网友评论

          本文标题:mac上nginx搭建

          本文链接:https://www.haomeiwen.com/subject/epzasqtx.html