部署Java项目记录

部署Java项目记录

前端部分

1、前端项目写好之后,开始项目构建,构建完会生成dist文件夹,
在这里插入图片描述

2、将生成好的dist文件夹放到服务器的自定义路径中(后面配置nginx的时候会用到)这样前端就部署完成了

在这里插入图片描述

后端部分

1、安装jdk

将下载好的jdk解压到指定文件夹中

tar -zxvf jdk-8u301-linux-x64.tar.gz

配置环境变量

vim /etc/profile

加入下面内容(JAVA_HOME路径记者换)

export JAVA_HOME=/usr/local/soft/jdk1.8.0_301
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

保存后刷新配置

source /etc/profile

查看是否安装完成

java -version
2、启动java程序

将打包好的Jar包放到服务器上,进行后台启动即可

nohup java -jar dts-admin-api-0.0.1-SNAPSHOT-exec.jar > log.file 2>&1 &

查看日志

tail -f log.file

查看进程

ps -ef | grep dts-admin-api-0.0.1-SNAPSHOT-exec.jar
3、安装nginx

系统平台:CentOS release 7.6 (Final) 64位。

1)安装编译工具及库文件
yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel
2)安装 PCRE

PCRE 作用是让 Nginx 支持 Rewrite 功能。

1、下载 PCRE 安装包,下载地址: http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz

cd /usr/local/src/
wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz

2、 解压安装包

tar zxvf nginx-1.6.2.tar.gz

3、进入安装包目录

cd nginx-1.6.2

4、编译安装

./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35
make
make install

5、查看nginx版本

[root@bogon nginx-1.6.2]# /usr/local/webserver/nginx/sbin/nginx -v

img

4、配置nginx

创建 Nginx 运行使用的用户 www:

/usr/sbin/groupadd www 
/usr/sbin/useradd -g www www

配置nginx.conf ,将/usr/local/webserver/nginx/conf/nginx.conf替换为以下内容

[root@bogon conf]#  cat /usr/local/webserver/nginx/conf/nginx.conf

user www www;
worker_processes 2; #设置值和CPU核心数一致
error_log /usr/local/webserver/nginx/logs/nginx_error.log crit; #日志位置和日志级别
pid /usr/local/webserver/nginx/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
events
{
  use epoll;
  worker_connections 65535;
}
http
{
  include 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';
  
#charset gb2312;
     
  server_names_hash_bucket_size 128;
  client_header_buffer_size 32k;
  large_client_header_buffers 4 32k;
  client_max_body_size 8m;
     
  sendfile on;
  tcp_nopush on;
  keepalive_timeout 60;
  tcp_nodelay on;
  fastcgi_connect_timeout 300;
  fastcgi_send_timeout 300;
  fastcgi_read_timeout 300;
  fastcgi_buffer_size 64k;
  fastcgi_buffers 4 64k;
  fastcgi_busy_buffers_size 128k;
  fastcgi_temp_file_write_size 128k;
  gzip on; 
  gzip_min_length 1k;
  gzip_buffers 4 16k;
  gzip_http_version 1.0;
  gzip_comp_level 2;
  gzip_types text/plain application/x-javascript text/css application/xml;
  gzip_vary on;
 
  #limit_zone crawler $binary_remote_addr 10m;
 #下面是server虚拟主机的配置
 server
  {
    listen 80;#监听端口
    server_name localhost;#域名
    index index.html index.htm index.php;
    root /usr/local/webserver/nginx/html;#站点目录
      location ~ .*\.(php|php5)?$
    {
      #fastcgi_pass unix:/tmp/php-cgi.sock;
      fastcgi_pass 127.0.0.1:9000;
      fastcgi_index index.php;
      include fastcgi.conf;
    }
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$
    {
      expires 30d;
  # access_log off;
    }
    location ~ .*\.(js|css)?$
    {
      expires 15d;
   # access_log off;
    }
    access_log off;
  }

}

检查配置文件nginx.conf的正确性命令:

/usr/local/webserver/nginx/sbin/nginx -t

img

5、启动nginx
/usr/local/webserver/nginx/sbin/nginx
6、nginx常用命令
/usr/local/webserver/nginx/sbin/nginx -t                   #检查命令正确性

/usr/local/webserver/nginx/sbin/nginx -s reload            # 重新载入配置文件
/usr/local/webserver/nginx/sbin/nginx -s reopen            # 重启 Nginx
/usr/local/webserver/nginx/sbin/nginx -s stop              # 停止 Nginx

vim /usr/local/webserver/nginx/conf/nginx.conf             # 编辑

域名备案

1、流程

1-)阿里云购买域名、

2-)域名购买完成后,进行ICP备案。

3-)备案完成后记得设置域名解析服务。

在这里插入图片描述

在这里插入图片描述

2、配置域名

nginx配置

user www www;
worker_processes 2; #设置值和CPU核心数一致
error_log /usr/local/webserver/nginx/logs/nginx_error.log crit; #日志位置和日志级别
pid /usr/local/webserver/nginx/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
events
{
  use epoll;
  worker_connections 65535;
}
http
{
    include 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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }


        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }

    server {
         listen       80;
         server_name  www.boe.site;

         location / {
             proxy_pass http://127.0.0.1:9999/demo;
             root   html;
             index  index.html index.htm;

             fastcgi_buffers 256 128k;
             chunked_transfer_encoding off;
         }


         location /admin {
            alias  /usr/local/dts-shop/front/;
            index  index.html index.htm;

            fastcgi_buffers 256 128k;
            chunked_transfer_encoding off;
         }
    }
   
     server {
         listen       443 ssl;
         server_name  www.boe.site;
         
         ssl_certificate      /usr/local/nginxSSL/11580006_www.boeiu.site.pem;
         ssl_certificate_key  /usr/local/nginxSSL/11580006_www.boeiu.site.key;

         ssl_session_cache    shared:SSL:1m;
         ssl_session_timeout  5m;

         ssl_ciphers  HIGH:!aNULL:!MD5;
         ssl_prefer_server_ciphers  on;

         location / {
             #root   html;
             root   /usr/local/dts-shop/front/dts-admin;
             index  index.html index.htm;
      
             fastcgi_buffers 256 128k;
             chunked_transfer_encoding off;
         }


         location /admin {
            alias  /usr/local/dts-shop/front/dts-admin;
            index  index.html index.htm;

            fastcgi_buffers 256 128k;
            chunked_transfer_encoding off;

            proxy_redirect off;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-Proto https;
            proxy_pass http://127.0.0.1:8083/demo/admin;
         }
    }

    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
}
3、nginx配置好保存重启测试。结束。

问题记录

1、nginx配置完,通过域名访问,访问不到

Java服务正常启动,阿里云安全组端口放开的,ngxin日志没有错误提示,就是访问不到,后来通过nslookup命令发现没有设置DNS解析

nslookup "your 域名"
2、通过域名访问后台,但是发现调用验证码接口,响应:no data found for resource with given identifier

在这里插入图片描述

以为是后台接口有问题,访问了下,结果接口是正常返回的

在这里插入图片描述

然后看了眼页面控制台,发现是因为页面是通过 HTTPS 加载的,但是有一个 XMLHttpRequest 请求是通过 HTTP 发起的,而不是 HTTPS,导致浏览器拒绝加载该请求。

在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值