这是本文档旧的修订版!
Nginx (“engine x”) 是一个高性能的HTTP和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 服务器。 Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,第一个公开版本0.1.0发布于2004年10月4日。其将源代码以类BSD许可证的形式发布,因它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名。2011年6月1日,nginx 1.0.4发布。
Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行。由俄罗斯的程序设计师Igor Sysoev所开发,供俄国大型的入口网站及搜索引擎Rambler(俄文:Рамблер)使用。其特点是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页服务器中表现较好,中国大陆使用nginx网站用户有:百度、新浪、网易、腾讯等。
本地系统:Ubuntu 14.04.2,安装命令:
apt-get install nginx#需要root权限
自动安装结束
root@iZ23goxo66aZ:/usr/share/nginx# whereis nginx #输出以下信息 /usr/sbin/nginx #命令 /etc/nginx #配置文件目录 /usr/share/nginx #html所在目录,日志也可以指定这里 /usr/share/man/man1/nginx.1.gz #man操作手册
root@iZ23goxo66aZ:~# nginx -h #查看帮助 nginx version: nginx/1.4.6 (Ubuntu) #当前版本 Usage: nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives] Options: -?,-h : this help -v : show version and exit -V : show version and configure options then exit -t : test configuration and exit -q : suppress non-error messages during configuration testing -s signal : send signal to a master process: stop, quit, reopen, reload -p prefix : set prefix path (default: /usr/share/nginx/) -c filename : set configuration file (default: /etc/nginx/nginx.conf) -g directives : set global directives out of configuration file
root@iZ23goxo66aZ:~# nginx -v #查看版本 nginx version: nginx/1.4.6 (Ubuntu)
root@iZ23goxo66aZ:~# nginx -V #查看版本以及可配置参数 nginx version: nginx/1.4.6 (Ubuntu) built by gcc 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04) TLS SNI support enabled configure arguments: --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_spdy_module --with-http_sub_module --with-http_xslt_module --with-mail --with-mail_ssl_module
root@iZ23goxo66aZ:~# nginx -t #测试nginx配置文件是否正确 nginx: the configuration file /etc/nginx/nginx.conf syntax is ok #is ok说明配置文件正确 nginx: configuration file /etc/nginx/nginx.conf test is successful #测试通过
root@iZ23goxo66aZ:~# nginx -s reload #更新配置文件后,不需要重启nginx,直接重新加载配置文件
root@iZ23goxo66aZ:~# nginx -s stop #关闭nginx
root@iZ23goxo66aZ:~# nginx #启动nginx
root@iZ23goxo66aZ:/etc/nginx# cp nginx.conf nginx.conf.bak.20160120 #备份配置文件,但是基本不修改这个配置文件
root@iZ23goxo66aZ:/etc/nginx# vim /etc/nginx/sites-enabled/default #基本会修改这个配置文件配置跳转和负载均衡,或者新建配置文件在sites-available中,再在sites-enabled中创建软链接