Nginx (engine x) 是一个高性能的HTTP和反向代理服务,也是一个IMAP/POP3/SMTP服务。其他信息请自行百度。
下面介绍一下,在CentOS7.4 的环境下,安装nginx-1.14.0的方法,供初学者借鉴。
【前提条件】
安装zlib 库、pcre,c++ 库等。在线安装方法:
yum -y install pcre-devel openssl openssl-devel zlib-devel
有时候部分机器会报告异常: ./configure: error: C compiler cc is not found
执行如下命令:
yum -y install gcc gcc-c++ autoconf automake make
【安装nignx】
上传nginx-1.14.0.tar.gz至服务器文件夹,这里以/alidata/software 目录为例:
# tar xvf nginx-1.14.0.tar.gz
# cd nginx-1.14.0
# ./configure --prefix=/alidata/service/nginx-1.14.0
(注意上面的安装位置/alidata/service/nginx-1.14.0,可以根据自己的需要设置)
# make
# make install
如果没有什么异常的话,恭喜你,安装成功。
【备注】如果要配置SSL证书的话,会报告如下的异常
nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module
则在安装nginx的时候,要加上对应的参数,如下语句:
./configure --prefix=/alidata/service/nginx-1.14.0 --with-http_ssl_module
【修改ngnix.conf配置文件】
具体的修订方法,请自行百度一下方案。这里仅仅给出个简单的配置样例,用于端口转发。
替换掉 /alidata/service/nginx-1.14.0/conf 下面的文件
user nobody; worker_processes 2; error_log /alidata/service/nginx-1.14.0/logs/error.log; pid /alidata/service/nginx-1.14.0/logs/nginx.pid; worker_rlimit_nofile 65536; events { use epoll; worker_connections 65536; } http { include mime.types; default_type application/octet-stream; client_max_body_size 100m; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /alidata/service/nginx-1.14.0/logs/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; map $http_upgrade $connection_upgrade { default upgrade; '' close; } upstream xinghansoft { ip_hash; server 114.115.246.89:8088; } server { listen 80; server_name 114.115.246.89:8088; charset utf-8; location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504; proxy_connect_timeout 150s; proxy_read_timeout 150s; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://xinghansoft; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } } }
【启动nginx】
# cd /alidata/service/nginx-1.14.0 # ./nginx 启动 # ./nginx -s stop 停止 # ./nginx -s reload 重启
没有异常的话,初始操作完成。
【特殊场景】
有些时候,为了应对GET请求,携带参数过大的需求,需要调整一下conf的配置,可以加入配置
client_header_buffer_size 512k; large_client_header_buffers 4 512k;