NGINX官网
以下列举了三个网址,分别是:NGINX官网,下载网址及官方文档。
官方网站:http://nginx.org/
下载网址:http://nginx.org/en/download.html
官方文档:http://nginx.org/en/docs/
下载NGINX
通过官方下载地址,可获得nginx源码包。
在windows中下载,其中NGINX分为Linux版本和Windows版本,按照需求下载相应版本的NGINX即可。
Linux下载,直接右击Linux对应的NGINX,右击复制链接地址,之后在Linux中通过wget命令下载即可。
wget http://nginx.org/download/nginx-1.19.0.tar.gz
安装环境
注:网络yum源或本地yum源都可。
通过软件仓库安装NGINX所需的依赖包
yum install -y gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre pcre-devel make automake
若是Linux自身的网络yum源下载缓慢,可通过==>配置国内yum源地址<==转用国内yum源。
创建NGINX服务用户,负责程序的正常运行。
groupadd www
useradd -g www www -s /sbin/nologin
解压,编译,安装
解压
tar zxf nginx-1.19.0.tar.gz
cd nginx-1.19.0/
预编译
注:列举了一些较为常用模块,详细可查看NGINX官方文档
./configure --prefix=/usr/local/nginx --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-pcre --with-http_ssl_module --with-http_gzip_static_module --user=www --group=www
配置项说明:
–prefix:nginx安装路径
–with-http_dav_module:通过WebDAV协议提供文件管理自动化,默认情况下未构建此模块。
–with-http_stub_status_module:提供对NGINX基本状态信息的访问,默认情况下未构建此模块。
–with-http_addition_module:过滤器,可在响应之前和之后添加文本,默认情况下未构建此模块。
–with-http_sub_module:允许一些其他字符串替换NGINX中的指定字符串来修改相应,默认情况下未构建此模块。
–with-http_flv_module:为Flash Video(FLV)文件提供伪流服务器端支持,默认情况下未构建此模块。
–with-http_mp4_module:该 模块为MP4文件提供伪流服务器端支持,默认情况下未构建此模块。
–with-pcre:强制使用PCRE库。
–with-http_ssl_module:启用构建将HTTPS协议支持添加 到HTTP服务器的模块的功能,默认情况下未构建此模块,需要OpenSSL库来构建和运行此模块。
–with-http_gzip_static_module:支持发送.gz扩展名为" "的预压缩文件,而不是常规文件,默认情况下未构建此模块。
–user:NGINX服务运行使用的用户,默认用户名为nobody。
–group:NGINX服务运行使用的组,默认情况下为nginx运行用户的名称。
预编译完成后,查看是否执行成功
echo $?
0 #除0外的任何值都表示没有执行成功
编译并安装
make ; make install
启动及测试
安装完成后,就可以通过nginx的控制脚本启动了。
控制脚本的名称为nginx,路径位于/usr/local/nginx/sbin/nginx。可以看到其位于nginx的sbin目录下,其表示除管理员用户外,其他用户无法启动,除非是由其他用户进行的编译安装。
为NGINX控制脚本设置PATH变量
ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/
查看nginx控制脚本命令帮助
nginx -h
nginx version: nginx/1.19.0
Usage: nginx [-?hvVtTq] [-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
-T : test configuration, dump it 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/local/nginx/)
-c filename : set configuration file (default: conf/nginx.conf)
-g directives : set global directives out of configuration file
一些常用的NGINX控制语句:
nginx -t:检测配置文件语法是否出错
nginx:启动NGINX服务
nginx -s stop:关闭NGINX服务
nginx -s reload:重载NGINX配置(在nginx配置文件修改时使用)
启动NGINX
nginx
查看端口是否存在
netstat -anput | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 5774/nginx: master
访问测试
curl 127.0.0.1
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
以上就是NGINX安装全过程。