CentOS安装Nginx
一、安装环境
yum -y install gcc gcc-c++ make libtool zlib zlib-devel openssl openssl-devel pcre pcre-devel
二、下载Nginx版本
1.官网直接下载.tar.gz
安装包,地址:nginx: download
2.使用wget
命令下载
wget -c https://nginx.org/download/nginx-1.18.0.tar.gz
3.网盘下载
链接:https://pan.baidu.com/s/1C3wfnqAgE2QZgyRPd3zU-w
提取码:6x06
三:解压
tar -zxvf nginx-1.18.0.tar.gz
cd nginx-1.18.0
四:配置
1.不需要SSL
./configure --prefix=/usr/local/nginx
2.需要SSL
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
五:编译安装
make && make install
六:启动Nginx
# 启动
cd /usr/local/nginx/sbin
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
# 重启
/usr/local/nginx/sbin/nginx -s reload
# 停止
/usr/local/nginx/sbin/nginx -s stop
七:代理配置
1.修改nginx.conf配置
vim /usr/local/nginx/conf/nginx.conf
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#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 logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
#侦听测试系统的80端口
listen 80;
server_name 192.167.8.105;
#全量匹配(名称必须完整) 注意105系统必须不包含该接口否则冲突 如有其他匹配要求可百度
location /api/devPort/getRR {
proxy_pass http://192.168.39.103:8080;
#允许所有跨域
add_header 'Access-Control-Allow-Origin' '*';
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
#对aspx后缀的进行负载均衡请求
location / {
#跟目录地址默认打开地址
proxy_pass http://192.167.8.105:80;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 100m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 300;
proxy_read_timeout 300;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
八:设置开机启动
1.即在rc.local
增加启动代码就可以了。
vim /etc/rc.local
增加一行 /usr/local/nginx/sbin/nginx