1、基础环境是否安装
创建用户:
groupadd -g 5222 app
useradd -u 5219 nginx usermod -G app nginxyum list installed
2、安装基础环境,安装C++编译环境
yum -y install gcc automake autoconf libtool make
yum install gcc-c++
3、下载安装软件
下载nginx: wget http://nginx.org/download/nginx-1.8.0.tar.gz
下载openssl : wget http://www.openssl.org/source/openssl-fips-2.0.9.tar.gz 下载zlib : wget http://zlib.net/zlib-1.2.8.tar.gz 下载pcre : wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz4、安装pcre、zlib、openssl
解压,配置、编译、安装
./config && make && make install
./configure && make && make install
5、安装nginx
./configure && make && make install
./configure --prefix=/你的安装目录 --add-module=/第三方模块目录
/usr/local/nginx/sbin/nginx -V
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module make
6、启动nginx
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
检测配置文件(注意不需要加配置文件)
/usr/local/nginx/sbin/nginx -t 重新加载配置文件(不停止服务) /usr/local/nginx/sbin/nginx -s reloadnginx -s stop :快速停止nginx
quit :完整有序的停止nginx查看日志:
/usr/local/nginx/logs
出现错误提示
[root lib]# error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory原因 在RedHat 64位机器上nginx读取的pcre文件为/lib64/libpcre.so.1文件,默认安装pcre时libpcre.so文件安装在/usr/local/lib/目录下,所以输入/opt/nginx/sbin/nginx -V 找不到文件路径!!
1.首先确定安装了pcre.
2.切换路径: cd /usr/local/lib 执行 ln -s /usr/local/lib/libpcre.so.1 /lib64/
3.root权限下添加软链接 /usr/local/lib/libpcre.so.1 到 /lib64/ : ln -s /usr/local/lib/libpcre.so.1 /lib64/
7、反向代理
location /xxx/xx/ {
proxy_pass http://xxx.xxx.xxx.xxx:8090/; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504; proxy_max_temp_file_size 0; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; }Nginx负载配置:
#gzip on;
upstream tomcat { server 10.2.20.63:8080 server 10.2.20.64:8080; } server { listen 80; server_name http://tomcat; charset utf-8; location / { root html; index index.html index.htm; proxy_pass http://tomcat;proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_set_header X-Real-IP $remote_addr; client_max_body_size 100m; } location ~ ^/(WEB-INF)/ { deny all; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /var/www/html/; } }