怎样在Linux服务器上部署自己的项目?(超详细)

14次阅读

1、前端部署。使用 Xftp 工具将前端打包完成的 dist 文件夹,上传至服务器的 /usr/local/web 文件夹下。
修改 Nginx 的配置文件nginx.conf。位于目录/etc/nginx
怎样在Linux服务器上部署自己的项目?(超详细)插图
修改配置如下:

# For more information on configuration, see: # * Official English Documentation: http://nginx.org/en/docs/ # * Official Russian Documentation: http://nginx.org/ru/docs/ user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; # Load dynamic modules. See /usr/share/doc/nginx/README.dynamic. include /usr/share/nginx/modules/*.conf; events {worker_connections 1024;} http {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 /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; # Load modular configuration files from the /etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. include /etc/nginx/conf.d/*.conf; server {listen 80 default_server; listen [::]:80 default_server; server_name 118.31.187.5; # root /usr/share/nginx/html; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / {root /usr/local/web/dist; try_files $uri $uri/ /index.html; index index.html;} location /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_pass http://localhost:8088/;} # error_page 404 /404.html; # location = /404.html {#} error_page 500 502 503 504 /50x.html; location = /50x.html {root html;} } # Settings for a TLS enabled server. # # server {# listen 443 ssl http2 default_server; # listen [::]:443 ssl http2 default_server; # server_name _; # root /usr/share/nginx/html; # # ssl_certificate "/etc/pki/nginx/server.crt"; # ssl_certificate_key "/etc/pki/nginx/private/server.key"; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 10m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # # # Load configuration files for the default server block. # include /etc/nginx/default.d/*.conf; # # location / {#} # # error_page 404 /404.html; # location = /404.html {#} # # error_page 500 502 503 504 /50x.html; # location = /50x.html {#} # } } 

改动的地方如下:

 location / {root /usr/local/web/dist; try_files $uri $uri/ /index.html; index index.html;} 
 location /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_pass http://localhost:8088/;} 

执行如下命令,重新加载 Nginx 使其生效。

nginx -s reload 

2、后端部署。使用 Xftp 工具将打包完成的 jar 包,上传至服务器的/usr/local/web 目录下面。
使用后台的方式启动后端工程。

nohup java -jar xx_web.jar >/dev/null 2>&1 & 

注:阿里云服务器需要配置安全组,并支持端口访问;比如 80,8080,3306、6379 端口等。


测试

在浏览器的地址栏中,访问 IP,即可进入后台管理系统!!!

原文链接:https://www.cnblogs.com/xxkfz/p/14967705.html

正文完
 
追风者
版权声明:本站原创文章,由 追风者 2024-01-02发表,共计2745字。
转载说明:声明:本站内容均来自互联网,归原创作者所有,如有侵权必删除。 本站文章皆由CC-4.0协议发布。