总结
yum -y install pcre-devel openssl openssl-devel
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
具体
单独安装nginx,来处理大量的下载请求。单独在Centos7安装nginx遇到的rewrite和HTTP cache错误解决办法:
向Linux传入文件:nginx-1.19.1.tar.gz
解压文件
进入解压后的文件夹执行下面命令:
./configure
安装Nginx时报错
./configure: error: the HTTP rewrite module requires the PCRE library.
安装pcre-devel解决问题
yum -y install pcre-devel
错误提示:./configure: error: the HTTP cache module requires md5 functions
from OpenSSL library. You can either disable the module by using
–without-http-cache option, or install the OpenSSL library into the system,
or build the OpenSSL library statically from the source with nginx by using
–with-http_ssl_module --with-openssl=
解决办法:
yum -y install openssl openssl-devel
总结:
yum -y install pcre-devel openssl openssl-devel
./configure
make
make install
后面两个命令可以用如下命令代替:
make && make install
进入文件夹
/usr/local/nginx/conf
编辑配置文件
vi nginx.conf
添加如下代码(woniusales根据项目名称改,域名为自己的域名,
upstream woniusales {
#ip_hash;
server 192.168.40.128:8080 weight=1;
server 192.168.40.128:28080 weight=1;
}
两台服务器(端口不一样)
添加完后的效果
继续修改
location /woniusales {
root html;
index index.html index.htm;
proxy_pass http://woniusales/woniusales;
}
修改完后的效果
图中第一个woniu是指上面可执行的woniu应用,第二个woniu是我们定义的nginx的访问地址(这个可以随意改)
显示nginx位置(命令)
whereis nginx
[root@localhost sbin]# whereis nginx
nginx: /usr/local/nginx
执行测试配置命令
/usr/local/nginx/sbin/nginx -t
[root@localhost sbin]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
特别强调一下:进到sbin目录下,通过./nginx启动.
上面的 /usr/local/nginx/sbin/nginx -t 不是启动nginx的操作,该操作只是用来测试nginx的配置是否正确
关闭nginx命令: ./nginx -s stop
服务器nginx 引入ssl配置时,报错:
nginx启动报"ssl parameter requires ngx_http_ssl_module":
原因:nginx缺少http_ssl_module模块,编译安装的时候带上–with-http_ssl_module配置就行了
使用nginx -V查询当前Nginx的编译配置信息,configure arguments: 后面为当前运行Nginx的配置信息
1、查找配置位置
(base) [root@iZxpl4sxxnloovZ nginx-1.8.0]# nginx -V
nginx version: nginx/1.8.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
configure arguments: --prefix=/usr/local/nginx
2、 切换到源码目录:
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module