博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MacOS 下 Nginx 安装记录
阅读量:7192 次
发布时间:2019-06-29

本文共 4469 字,大约阅读时间需要 14 分钟。

之前写过:

最近工作办公电脑换了 Mac,刚好有机会实践一下。

安装非常简单:

sudo port install nginx
或者使用:

sudo brew install nginx
使用brew可能还需要:

brew search nginx
port 和 brew 是 Mac 下两大包管理工具,使用它们安装软件非常的方便,类似 CentOS下的 yum ,Ubuntu 下的 apt-get 。

安装完成会输出以下提示:我是使用 port 安装的:

nginx has the following notes:    A set of sample configuration files has been installed in /opt/local/share/nginx/examples.        Additionally, the files nginx.conf, mime.types, fastcgi.conf have been copied to /opt/local/etc/nginx if they didn't    exist yet.    Adjust these files to your needs before starting nginx.
查看可执行文件 目录:

which nginx/opt/local/sbin/nginx

/opt/local/share/nginx/examples 目录下是配置示例文件;

/opt/local/etc/nginx 实际使用的配置文件 在这个目录下;

编辑配置&重新加载配置:

sudo vi nginx.conf sudo nginx -s reload
配置文件 示例:我改了下端口和默认文档

#user  nobody;worker_processes  1;#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;    server {        listen       88;        server_name  localhost;        #charset koi8-r;        #access_log  logs/host.access.log  main;        location / {            root   share/nginx/html;            index  default.htm 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   share/nginx/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           share/nginx/html;        #    fastcgi_pass   127.0.0.1:9000;        #    fastcgi_index  index.php;        #    include        fastcgi.conf;        #}        # deny access to .htaccess files, if Apache's document root        # concurs with nginx's one        #        #location ~ /\.ht {        #    deny  all;        #}    }    # another virtual host using mix of IP-, name-, and port-based configuration    #    #server {    #    listen       8000;    #    listen       somename:8080;    #    server_name  somename  alias  another.alias;    #    location / {    #        root   share/nginx/html;    #        index  index.html index.htm;    #    }    #}}

常用命令

nginx  启动,可能需要权限,使用 sudo nginx

nginx -V 查看Nginx的版本号

大V显示的是非常详细的信息,小v只显示第一行:

nginx version: nginx/1.11.10built with OpenSSL 1.0.2k  26 Jan 2017TLS SNI support enabledconfigure arguments: --prefix=/opt/local --with-cc-opt='-I/opt/local/include -Os' --with-ld-opt='-L/opt/local/lib -Wl,-headerpad_max_install_names' --conf-path=/opt/local/etc/nginx/nginx.conf --error-log-path=/opt/local/var/log/nginx/error.log --http-log-path=/opt/local/var/log/nginx/access.log --pid-path=/opt/local/var/run/nginx/nginx.pid --lock-path=/opt/local/var/run/nginx/nginx.lock --http-client-body-temp-path=/opt/local/var/run/nginx/client_body_temp --http-proxy-temp-path=/opt/local/var/run/nginx/proxy_temp --http-fastcgi-temp-path=/opt/local/var/run/nginx/fastcgi_temp --http-uwsgi-temp-path=/opt/local/var/run/nginx/uwsgi_temp --with-ipv6 --with-http_flv_module --with-http_mp4_module --with-http_secure_link_module --with-http_ssl_module

nginx -s quit 正常停止或关闭Nginx

nginx -s stop 快速停止或关闭Nginx

nginx -s reload 重新加载配置文件

nginx -t 测试nginx.conf配置文件是否正确

nginx -s stop 和 -s quit 有什么区别呢?

quit 是一种优雅的退出方式。优雅在哪里呢?

Quit is a graceful shutdown. Nginx finishes serving the open connections before shutdown

Stop is a quick shutdown where is terminates in between serving the connection

当nginx收到quit信号后,首先停止接受连接,不再接受新的连接请求了;然后进程如果还在服务中(也就是还有访问请求没有处理并响应完成),那么就不会关闭该进程,直到进程完成服务为止。当所有未完成的请求都处理完成了,再退出。

而接收到 Stop 信号后就不管那么多了,直接退出进程。

quit 就好比到下班时间了,手头还有点工作没做完,做完了再走;stop 是下班就走。 

推荐阅读:

======================文档信息========================

版权声明:非商用自由转载-保持署名-注明出处

署名(BY) :testcs_dn(微wx笑)

文章出处:[无知人生,记录点滴](http://blog.csdn/testcs_dn)

==============欢迎关注我的个人订阅号(微wx笑)============

你可能感兴趣的文章
js事件委托
查看>>
计算机硬件
查看>>
gattAttribute_t 含义 中文解释
查看>>
jquery 选择器汇总
查看>>
Nodejs 学习资料
查看>>
设计模式(三) 抽象工厂模式
查看>>
Hbase之修改表结构
查看>>
通过浏览器学习前端的小技巧
查看>>
APP开发之AngularJS学习
查看>>
Sass:RGB颜色函数-Mix()函数
查看>>
phpMyAdmin 错误 缺少 mysqli 扩展。请检查 PHP 配置
查看>>
Win7网上邻居提示未授予用户在此计算机上的请求登录类型解决办法
查看>>
golang包快速生成base64验证码
查看>>
Visual studio 下C++工程相关经验
查看>>
七、SSR(服务端渲染)
查看>>
django--app(六)
查看>>
洛谷P3379 【模板】最近公共祖先(LCA)
查看>>
获取一个表单字段中多条数据并转化为json格式
查看>>
c#中的变量,属性,字段
查看>>
JS实现延迟载入图片
查看>>