一、停止 nginx 服务并关闭开机自启动
systemctl stop nginx
systemctl disable nginx
二、安装 apache
yum install httpd
systemctl restart httpd
三、部署前端
/var/www/html/ 下创建 test 目录,将 test-ui.zip 解压到该目录下
四、部署后端
执行命令:
nohup java -jar xxx.jar -&
注:后端应用运行在 18080 端口。
五、配置 httpd.conf
修改 /etc/httpd/conf/httpd.conf,在文件最后增加以下内容:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule rewrite_module modules/mod_rewrite.so
<Directory "/var/www/html/isms2">
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.html [L]
AllowOverride All
Require all granted
</Directory>
<VirtualHost *:80>
ServerName localhost
ProxyPass /test/prod-api http://localhost:18080
ProxyPassReverse /test/prod-api http://localhost:18080
</VirtualHost>
注:Nginx 的配置如下:
server {
listen 80;
server_name localhost;
location /test {
alias /home/project/ui;
try_files $uri $uri/ /test/index.html;
index index.html index.htm;
}
location /test/prod-api/ {
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_connect_timeout 100;
proxy_read_timeout 100;
proxy_send_timeout 100;
proxy_pass http://localhost:18080/;
}
}