CentOs7 配置Nginx 部署Java前后端项目
1.下载Nginx
wget http://nginx.org/download/nginx-1.19.6.tar.gz
tar -xzf nginx-1.19.6.tar.gz
cd nginx-1.19.6
2.安装nginx的依赖环境
yum update
yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
./configure
./configure --with-http_ssl_module
make & make install
/usr/local/nginx/sbin/nginx -V
3.配置Nginx
cd /usr/local/nginx/conf
vi nginx.conf
Nginx的配置文件(https协议)
有几点注意项:
1.location /backend/ 代理的是后端, location / 代理的是前端 2.backend 得在后台程序中的application.yml 中定义 3.启动项目之后,开启了防火墙的话,一定要开放443、80和项目中的端口号 4.前端访问后端的地址得是VUE_APP_BASE_API = 'https://192.168.3.105/backend' ,https协议的,不然会出现协议混淆,访问不到后端接口。
server {
listen 443 ssl;
server_name localhost;
ssl_certificate /usr/local/nginx/cer/server.crt;
ssl_certificate_key /usr/local/nginx/cer/server.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root /usr/local/nginx/html/dist;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location /backend/{
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8991;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
配置完之后,就启动Nginx
/usr/local/nginx/sbin
./nginx
./nginx -s reload
|