> 文章列表 > 如何将前、后端服务由Nginx转为Apache

如何将前、后端服务由Nginx转为Apache

如何将前、后端服务由Nginx转为Apache

目录

  • 一、停止 nginx 服务并关闭开机自启动
  • 二、安装 apache
  • 三、部署前端
  • 四、部署后端
  • 五、配置 httpd.conf

一、停止 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 onRewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule . index.html [L]AllowOverride AllRequire all granted
</Directory><VirtualHost *:80>ServerName localhostProxyPass /test/prod-api http://localhost:18080ProxyPassReverse /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/;}
}