您的位置:首页 > 运维架构 > Nginx

Nginx安装

2020-05-05 12:38 811 查看

安装Nginx

一、下载源码包

下载地址:http://nginx.org/en/download.html

Nginx官网提供了三个类型的版本

Mainline version:Mainline 是 Nginx 目前主力在做的版本,可以说是开发版
Stable version:最新稳定版,生产环境上建议使用的版本
Legacy versions:遗留的老版本的稳定版
wget http://nginx.org/download/nginx-1.12.2.tar.gz

二、安装编译环境

yum install -y gcc gcc-c++ pcre pcre-devel zlib zlib-devel  openssl openssl-devel

三、编译与安装

1、下载之后解压

tar -zxvf nginx-1.12.2.tar.gz

2、进入解压后的目录

cd nginx-1.12.2

3、配置安装选项

# 可通过`./configure --help | more ` 查看配置参数列表
# --prefix=/usr/local/nginx  指定安装目录,
# --with-http_stub_status_module 监控页面
# --with-http_ssl_module        ssl ,搭建https 时需要此模块
# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
./configure --help --prefix=/usr/local/nginx

4、编译并安装

make && make install

四、启动Nginx

进入nginx 目录,下面有4个目录

conf -- 配置文件

html -- 网页文件

logs -- 日志文件

sbin -- 主要二进制程序

# 进入目录
cd /usr/local/nginx/

# 启动nginx
sbin/nginx

浏览器访问,直接在地址栏写上服务器ip 即可,nginx 默认启动端口是80端口。

五、Nginx 命令

1、信号控制

语法:有如下两个

  • Kill -信号选项 nginx的主进程号
  • Kill -信号选项
    cat /usr/local/nginx/logs/nginx.pid

信号选项如下:

信号选项 选项说明
TERM, INT Quick shutdown
QUIT Graceful shutdown 优雅的关闭进程,即等请求结束后再关闭
HUP Configuration reload ,Start the new worker processes with a new configuration Gracefully shutdown the old worker processes 改变配置文件,平滑的重读配置文件
USR1 Reopen the log files 重读日志,在日志按月/日分割时有用
USR2 Upgrade Executable on the fly 平滑的升级
WINCH Gracefully shutdown the worker processes 优雅关闭旧的进程(配合USR2来进行升级)
栗子:
kill -QUIT $( cat /usr/local/nginx/logs/nginx.pid )
停止nginx

2、二进制文件加参数

参数 参数说明
-?, -h Print help.
-v Print version.
-V Print NGINX version, compiler version and configure parameters.
-t Don’t run, just test the configuration file. NGINX checks configuration for correct syntax and then try to open files referred in configuration.
-q Suppress non-error messages during configuration testing.
-s signal signal Send signal to a master process: stop -- 停止, quit -- 也是停止比较优雅, reopen -- 重新生成日志, reload -- 重新加载日志. (version >= 0.7.53)
-p prefix prefix Set prefix path (default: /usr/local/nginx/). (version >= 0.7.53)
-c filename filename Specify which configuration file NGINX should use instead of the default.
-g directives Set global directives. (version >= 0.7.4)
栗子:
/usr/bin/nginx -s stop
停止nginx

不明白可参考:https://www.nginx.com/resources/wiki/start/topics/tutorials/commandline/

六、可能出现的错误

1、缺少C语言环境

1、checking for C compiler cc ... not found

# 解决方法
yum install -y gcc gcc-c++

2、需要安装pcre pcre-devel,为了让nginx 支持 rewrite 这个模块

2、./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre= option。

# 解决方法
yum install -y pcre pcre-devel

3、安装 zlib zlib-devel ,为了让nginx 支持 gzip 模块

3、./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib= option

# 解决方法
yum install -y zlib zlib-devel

4、端口没开放

4、都没报错,但浏览器访问ip,访问不到。请检查80端口是否开放。可以用windows 的telnet 命令

telnet 你的服务器ip 80
,如果提示 telent 未找到,请百度搜 :开启telnet服务,这里就不多说了。

参考自:https://www.nginx.com/resources/wiki/start/topics/tutorials/commandline/

转载于:https://www.cnblogs.com/rstyro/articles/10715865.html

apkqfa6158 原创文章 0获赞 0访问量 737 关注 私信
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: