CentOS系统安装Nginx方法
1. 在CentOS系统上安装Nginx 对于CentOS 6环境,EPEL仓库已包含nginx的RPM包,但该版本通常较低。若需使用更新版本,可获取官方提供的RPM包,或通过源码进行编译安装。
Nginx常用编译参数详解
此外,也可选用经过二次开发且功能增强的Nginx衍生版本,例如淘宝开发的Tengine以及OpenResty,这些都是较为理想的选择。 1.1 常用编译参数
--prefix=PATH:用于指定Nginx的安装目录路径 --conf-path=PATH:设定nginx.conf配置文件的具体位置 --user=NAME:定义Nginx工作进程所属的用户名 --with-pcre:启用对PCRE正则表达式库的支持 --with-http_ssl_module:开启SSL模块以支持HTTPS --with-http_stub_status_module:启用状态监控模块 --with-http_realip_module:允许修改客户端请求头中的真实IP地址 --with-file-aio:激活文件异步I/O功能 --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
Nginx服务启动与关闭命令
1.2 Nginx的启动与关闭管理
启动Nginx服务的操作如下:
# nginx -c /etc/nginx/nginx.conf
关闭Nginx服务
# nginx -s stop
重新读取配置文件
# nginx -s reload
# pkill -HUP nginx
重新打开日志文件
# nginx -s reopen
# pkill -USR1 nginx
也可以从Nginx RPM包中提取/etc/init.d/nginx文件,修改其中的路径配置后即可直接使用:
# service nginx {start|stop|status|restart|reload|configtest|}
Windows系统部署Nginx步骤
2. 在Windows系统上安装Nginx 首先访问官网下载Nginx 1.0.11版本的Windows安装包,下载地址为:http://nginx.org/download/nginx-1.0.11.zip
下载完成后,将压缩包nginx-nginx1.0.11.zip解压至你偏好的根目录,并将解压后的文件夹名称重命名为nginx。
接着,执行以下操作步骤:
cd nginx
start nginx
至此,Nginx服务即已成功启动。打开任务管理器检查,可以看到两个nginx.exe进程正在运行,其占用的系统资源极少。随后打开浏览器,输入地址http://127.0.0.1/,即可看到Nginx友好的欢迎页面。
nginx -s stop // 停止nginx
nginx -s reload // 重新加载配置文件
nginx -s quit // 退出nginx