当前位置:   首页安装配置

Linux:在Linux和Windows系统上安装Nginx主机的教程

发布日期:2022-06-13 18:28 | 文章来源:源码之家

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:启用 File AIO
--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.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|}

2.在Windows系统上安装Nginx
首先去官网下载 nginx1.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


联系我们
关于使用场景和技术架构的更多咨询,请联系我们的销售和技术支持团队。
Yingsoo Host

在线
客服

在线客服:7*24小时在线

客服
热线

400-630-3752
7*24小时客服服务热线

关注
微信

关注官方微信
顶部