之前写过:
CentOS6.5下Nginx1.7.4安装记录
最近工作办公电脑换了 Mac,刚好有机会实践一下。
sudo port install nginx或者使用:
sudo brew install nginx使用brew可能还需要:
brew search nginxport 和 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.10 built with OpenSSL 1.0.2k 26 Jan 2017 TLS SNI support enabled configure 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配置文件是否正确
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 是下班就走。
推荐阅读:nginx signal 之 quit
======================文档信息========================
版权声明:非商用自由转载-保持署名-注明出处
署名(BY) :testcs_dn(微wx笑)
文章出处:[无知人生,记录点滴](http://blog.csdn.NET/testcs_dn)
==============欢迎关注我的个人微信订阅号(微wx笑)============