在Linux和Windows系统上安装Nginx服务器的教程
1.在CentOS系统上安装Nginx
在CentOS6版本的EPEL源中,已经加入了nginx的rpm包,不过此RPM包版本较低。如果需要更新版本,可以使用官方制作的rpm包,或者使用源码包编译安装。
还可以使用一些二次开发功能增强的nginx版本,例如淘宝的Tengine和OpenResty都是不错的选择。
1.1常用编译参数
--prefix=PATH:指定nginx的安装目录
--conf-path=PATH:指定nginx.conf配置文件路径
--user=NAME:nginx工作进程的用户
--with-pcre:开启PCRE正则表达式的支持
--with-http_ssl_module:启动SSL的支持
--with-http_stub_status_module:用于监控Nginx的状态
--with-http-realip_module:允许改变客户端请求头中客户端IP地址
--with-file-aio:启用FileAIO
--add-module=PATH:添加第三方外部模块
这里提供一个完整的编译方案:
--prefix=/usr/local/nginx\ --conf-path=/etc/nginx/nginx.conf\ --error-log-path=/var/log/nginx/error.log\ --http-log-path=/var/log/nginx/access.log\ --http-client-body-temp-path=/var/tmp/nginx/client_body\ --http-proxy-temp-path=/var/tmp/nginx/proxy\ --http-fastcgi-temp-path=/var/tmp/nginx/fastcgi\ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi\ --pid-path=/var/run/nginx.pid\ --lock-path=/var/lock/nginx\ --user=nginx\ --group=nginx\ --with-file-aio\ --with-http_ssl_module\ --with-http_realip_module\ --with-http_sub_module\ --with-http_gzip_static_module\ --with-http_stub_status_module\ --with-pcre
1.2nginx的启动和关闭
启动nginx:
#nginx-c/etc/nginx/nginx.conf
关闭nginx
#nginx-sstop
重读配置文件
#nginx-sreload #pkill-HUPnginx
重新打开日志文件
#nginx-sreopen #pkill-USR1nginx
还可以下载nginxRPM包中的/etc/init.d/nginx文件,修改路径后即可使用:
#servicenginx{start|stop|status|restart|reload|configtest|}
2.在Windows系统上安装Nginx
首先去官网下载nginx1.0.11的Windows版本,官网下载:http://nginx.org/download/nginx-1.0.11.zip
下载到软件包后,解压nginx-nginx1.0.11.zip包到你喜欢的根目录,并将目录名改为nginx。
然后,执行下列操作:
cdnginx startnginx这样,nginx服务就启动了。打开任务管理器,查看nginx.exe进程,有二个进程会显示,占用系统资源,那是相当的少。然后再打开浏览器,输入http://127.0.0.1/ 就可以看到nginx的欢迎页面了,非常友好
nginx-sstop//停止nginx nginx-sreload//重新加载配置文件 nginx-squit//退出nginx