Nginx运行环境需要用到一下环境变量依赖,安装前确保环境中有以下依赖:(gcc -c++配置和PCRE库)
PCRE是Nignx的rewrite模块和HTTP核心模块会用到的PCRE正则表达式;
安装:
shell> yum -y install gcc-c++
shell> yum -y install pcre pcre-devel zlib zlib-devel openssl openssl-devel
或者一次性安装四个依赖:
推荐:
shell> yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
shell> cd /usr/local/src
shell> wget http://nginx.org/download/nginx-1.17.7.tar.gz
shell> tar -xvzf nginx-1.17.7.tar.gz
shell> rm -f nginx-1.17.7.tar.gz
shell> wget https://www.openssl.org/source/openssl-1.0.2u.tar.gz
shell> tar -xvzf openssl-1.0.2u.tar.gz
shell> rm -f openssl-1.0.2u.tar.gz
shell> cd nginx-1.17.7
shell> ./configure
# 成功后显示如下信息
Configuration summary
+ using system PCRE library
+ using OpenSSL library: /usr/local/src/openssl-1.0.2u
+ using system zlib library
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx"
nginx configuration file: "/usr/local/nginx/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
shell> make && make install
shell> ln -sf /usr/local/nginx/sbin/nginx /usr/local/bin/nginx
shell> /usr/local/nginx/sbin/nginx -v
shell> nginx -v # 已创建软连接
shell> /usr/local/nginx/sbin/nginx
shell> nginx # 已创建软连接
shell> ps -ef|grep nginx
shell> nginx -s stop # 停止 nginx
shell> nginx -s reload # 重载 nginx
验证 Nginx 是否成功启动,可以在浏览器中打开 http://YOUR_IP,您将看到默认的 Nginx 欢迎页面,类似于下图所示:
注:Nginx 的默认欢迎页有好几种样式,和你安装的版本有关,所以大家只用关注这个页面的大标题就行了 Welcome to nginx!
错误提示1.:./configure: error: the HTTP rewrite module requires the PCRE library在第6步:./configure,预编译发生错误提示。
解决方案1:没有安装HTTP模块依赖,安装pcre-devel解决问题
shell> yum -y install pcre-devel
解决方案2:没有安装zlib-devel模块依赖,安装zlib-devel解决问题
shell> yum install -y zlib-devel
安装结束!
## 1,将nginx添加到yum repro库中
# rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
2,查看nginx信息
# yum info nginx
3,使用yum安装ngnix
# yum -y install nginx
4,启动nginx
# systemctl start nginx
[root@izbp1b498epn4trb75oykez ~]# vi /etc/nginx/conf.d/default.conf
添加一个新的server,这个配置主要是将监听80端口,将来自dev.jindll.com的请求转发到本地4355端口
server {
listen 80;
server_name dev.jindll.com;
location / {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_pass http://127.0.0.1:4355;
}
}
配置完成保存退出,然后重启nginx,使配置生效
# systemctl reload nginx.service