yum -y install gcc gcc-c++ make libtool zlib zlib-devel openssl openssl-devel pcre pcre-devel
1.官网直接下载.tar.gz
安装包,地址:nginx: download
2.使用wget
命令下载
wget -c https://nginx.org/download/nginx-1.22.1.tar.gz
tar -zxvf nginx-1.22.1.tar.gz
cd nginx-1.22.1
不需要SSL
./configure --prefix=/usr/local/nginx
需要SSL
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make
make install
# 启动
cd /usr/local/nginx/sbin/
./nginx
# 重启
./nginx -s reload
nginx.conf配置
user root;
worker_processes 1;
error_log /usr/local/nginx/logs/error.log warn;
#pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /usr/local/nginx/conf/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 /usr/local/nginx/logs/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_comp_level 3;
gzip_types text/plain text/css application/xml application/javascript application/x-javascript text/javascript;
include /usr/local/nginx/conf/conf.d/*.conf;
}
default.http.conf配置
server {
listen 80;
server_name xxx.cn www.xxx.cn;
client_max_body_size 150M;
location / {
root /home/busapp/ui/;
#index index.html;
# 解决vue打包项目后刷新404的问题
try_files $uri $uri/ /index.html =404;
}
location /api/ {
proxy_pass http://127.0.0.1:27071/;
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_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_connect_timeout 60s;
proxy_read_timeout 60s;
proxy_send_timeout 60s;
}
location /ptapi/ {
proxy_pass http://127.0.0.1:27071/;
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_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_connect_timeout 60s;
proxy_read_timeout 60s;
proxy_send_timeout 60s;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
配置SSL证书
# 创建证书目录
cd /usr/local/nginx/
mkdir cert
server {
listen 443 ssl;
server_name xxx.cn www.xxx.cn;
ssl_certificate /usr/local/nginx/7369597_xxx.cn.pem;
ssl_certificate_key /usr/local/nginx/7369597_xxx.cn.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
root /home/busapp/ui/;
index index.html;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
client_max_body_size 50M;
location /api/ {
proxy_pass http://127.0.0.1:27071/;
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_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_connect_timeout 60s;
proxy_read_timeout 60s;
proxy_send_timeout 60s;
}
location /ptapi/ {
proxy_pass http://127.0.0.1:27071/;
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_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_connect_timeout 60s;
proxy_read_timeout 60s;
proxy_send_timeout 60s;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
在rc.local
增加启动代码就可以了。
vim /etc/rc.local
增加一行 /usr/local/nginx/sbin/nginx
设置执行权限
chmod 755 rc.local
到这里,nginx就安装完毕了。
卸载Nginx
yum remove nginx
查看Nginx是否还存在
which nginx