下载nginx
https://nginx.org/en/download.html
安装依赖
yum install gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl openssl-devel
解压二进制包
tar -zxvf nginx-x.x.x.tar.gz
配置相关环境变量
cd nginx-x.x.x
./configure --prefix=/usr/local/nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module
编译
make && make install
查看编译结果,为0表示成功
echo $?
启动nginx
cd /usr/local/nginx/
./sbin/nginx -c ./conf/nginx.conf
ps -ef|grep nginx
配置http
server {
listen 80;
listen 443 ssl;
if ($scheme = http) {
return https://$host$request_uri;
}
ssl on;
ssl_certificate /path/to/crt;
ssl_certificate_key /path/to/key;
#ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers 自行添加;
ssl_prefer_server_ciphers on;
error_page 404 /404/404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location / {
proxy_buffering off;
add_header Cache-Control "no-cache, no-store";
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_pass http://127.0.0.1:8080;
proxy_set_header X-Forwarded-Proto $scheme;
fastcgi_intercept_errors on;
}
access_log /data/nginx_logs/access.log;
}