美文网首页
Mac 安装nginx

Mac 安装nginx

作者: 牧馬放飏 | 来源:发表于2019-01-06 17:53 被阅读6次

    1.搜索

    brew search nginx
    

    2.下载

    brew install nginx
    

    3.安装成功

    wukaijiedeAir:~ wukaijie$ brew install nginx
    Updating Homebrew...
    ==> Auto-updated Homebrew!
    Updated 1 tap (homebrew/core).
    ==> Updated Formulae
    emacs-clang-complete-async    libgxps                       lsdvd                         podofo
    less                          libmicrohttpd                 mozjpeg                       tcc
    
    ==> Installing dependencies for nginx: openssl and pcre
    ==> Installing nginx dependency: openssl
    ==> Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2q.high_sierra.bottle.tar.gz
    ######################################################################## 100.0%
    ==> Pouring openssl-1.0.2q.high_sierra.bottle.tar.gz
    ==> Caveats
    A CA file has been bootstrapped using certificates from the SystemRoots
    keychain. To add additional certificates (e.g. the certificates added in
    the System keychain), place .pem files in
      /usr/local/etc/openssl/certs
    
    and run
      /usr/local/opt/openssl/bin/c_rehash
    
    openssl is keg-only, which means it was not symlinked into /usr/local,
    because Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries.
    
    If you need to have openssl first in your PATH run:
      echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile
    
    For compilers to find openssl you may need to set:
      export LDFLAGS="-L/usr/local/opt/openssl/lib"
      export CPPFLAGS="-I/usr/local/opt/openssl/include"
    
    ==> Summary
    🍺  /usr/local/Cellar/openssl/1.0.2q: 1,794 files, 12.1MB
    ==> Installing nginx dependency: pcre
    ==> Downloading https://homebrew.bintray.com/bottles/pcre-8.42.high_sierra.bottle.tar.gz
    ######################################################################## 100.0%
    ==> Pouring pcre-8.42.high_sierra.bottle.tar.gz
    🍺  /usr/local/Cellar/pcre/8.42: 204 files, 5.3MB
    ==> Installing nginx
    ==> Downloading https://homebrew.bintray.com/bottles/nginx-1.15.8.high_sierra.bottle.tar.gz
    ######################################################################## 100.0%
    ==> Pouring nginx-1.15.8.high_sierra.bottle.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
    ==> Caveats
    ==> openssl
    A CA file has been bootstrapped using certificates from the SystemRoots
    keychain. To add additional certificates (e.g. the certificates added in
    the System keychain), place .pem files in
      /usr/local/etc/openssl/certs
    
    and run
      /usr/local/opt/openssl/bin/c_rehash
    
    openssl is keg-only, which means it was not symlinked into /usr/local,
    because Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries.
    
    If you need to have openssl first in your PATH run:
      echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile
    
    For compilers to find openssl you may need to set:
      export LDFLAGS="-L/usr/local/opt/openssl/lib"
      export CPPFLAGS="-I/usr/local/opt/openssl/include"
    
    ==> nginx
    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
    

    4.查看nginx版本

    $ nginx -v
    nginx version: nginx/1.15.8
    

    5.启动nginx

    $ nginx -v
    nginx version: nginx/1.15.8
    
    image.png

    6.重加载nginx

    sudo nginx -s reload
    

    7.关闭nginx

    sudo nginx -s stop
    

    8.端口冲突,重新设置端口号

    The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
    nginx can run without sudo
    

    这是安装成功的提示,修改端口的文件在' /usr/local/etc/nginx/nginx.conf '

    vim /usr/local/etc/nginx/nginx.conf 
    

    nginx.conf,我修改端口为:8090

    server {
            listen       8090;
            server_name  localhost;
    
            #charset koi8-r;
    
            #access_log  logs/host.access.log  main;
    
            location / {
                root   html;
                index  index.html index.htm;
            }
    
            #error_page  404              /404.html;
    
            # redirect server error pages to the static page /50x.html
            #
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
    
            # proxy the PHP scripts to Apache listening on 127.0.0.1:80
            #
            #location ~ \.php$ {
            #    proxy_pass   http://127.0.0.1;
            #}
    
            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            #
            #location ~ \.php$ {
            #    root           html;
            #    fastcgi_pass   127.0.0.1:9000;
            #    fastcgi_index  index.php;
            #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            #    include        fastcgi_params;
            #}
    
            # deny access to .htaccess files, if Apache's document root
            # concurs with nginx's one
            #
            #location ~ /\.ht {
            #    deny  all;
            #}
    }
    

    9.nginx常用的命令

    nginx -s reload       重新加载配置
    nginx -s reopen       重启
    nginx -s stop           停止
    nginx -s quit            退出
    nginx -V                    查看版本,以及配置文件地址
    nginx -v                    查看版本
    nginx -c filename    指定配置文件
    nginx -h                    帮助
    

    相关文章

      网友评论

          本文标题:Mac 安装nginx

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