1、前端项目打包
npm run build
1.1、打包出错
出现这个错误是因为 node.js V17版本中最近发布的OpenSSL3.0, 而OpenSSL3.0对允许算法和密钥大小增加了严格的限制,可能会对生态系统造成一些影响。在node.js V17以前一些可以正常运行的的应用程序,但是在 V17 版本可能会抛出这个异常。
1.2、解决办法
1、尝试卸载Node.js 17+版本并重新安装Node.js 16+版本,然后再重新启动
2、在执行运行项目命令之前,先运行这个命令:
Linux & Mac OS:
export NODE_OPTIONS=--openssl-legacy-provider
windows命令提示符:
set NODE_OPTIONS=--openssl-legacy-provider
唯一不足,是每次启动项目都要运行。
打包后,前端项目出现dist文件。
2、下载nginx
在安装nginx前首先要确认系统中安装了gcc、pcre-devel、zlib-devel、openssl-devel
yum install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
下载nginx,登录网站查看nginx版本,linux下载,并解压
wget http://nginx.org/download/nginx-1.20.1.tar.gz
tar -zxvf nginx-1.20.1.tar.gz
cd nginx-1.20.1/
3、安装nginx
安装nginx,进入nginx-1.20.1的文件夹,执行安装;
./configure --prefix=/opt/nginx,路径可修改,路径为实际安装的nginx所在。
[root@localhost nginx-1.20.1]# ./configure --prefix=/opt/nginx
[root@localhost nginx-1.20.1]#
[root@localhost nginx-1.20.1]# make
[root@localhost nginx-1.20.1]#
[root@localhost nginx-1.20.1]# make install
[root@localhost nginx-1.20.1]#
进入安装的nginx文件夹,进入sbin文件夹,测试配置是否通过。
[root@localhost nginx]# cd sbin
[root@localhost sbin]#
[root@localhost sbin]# ./nginx -t
nginx: the configuration file /opt/erp/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /opt/erp/nginx/conf/nginx.conf test is successful
[root@localhost sbin]#
[root@localhost sbin]# ls
nginx
[root@localhost sbin]#
执行命令,启动nginx
#启动nginx
[root@localhost sbin]# ./nginx
#停止
[root@localhost sbin]# ./nginx -s stop
#重启
[root@localhost sbin]# ./nginx -s reload
4、上传文件到指定文件夹
将前端打包出的 dist 文件上传到服务器 nginx安装位置下的html文件夹下 /opt/erp/nginx/html/
5、配置nginx.conf重启nginx
找到nginx下conf文件夹下的nginx.conf文件。
[root@localhost sbin]# cd ../
[root@localhost nginx]# ls
client_body_temp conf fastcgi_temp html logs proxy_temp sbin scgi_temp uwsgi_temp
[root@localhost nginx]# cd conf
[root@localhost conf]# ls
fastcgi.conf fastcgi_params.default mime.types nginx.conf.default uwsgi_params
fastcgi.conf.default koi-utf mime.types.default scgi_params uwsgi_params.default
fastcgi_params koi-win nginx.conf scgi_params.default win-utf
[root@localhost conf]#
打开,编辑。
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
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 85;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /opt/erp/nginx/html/dist/;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
location /jshERP-boot {
proxy_pass http://localhost:9999;
}
#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;
#}
}
# 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;
# }
#}
}
主要注意以下几个:
如果有多个服务,就配置多个server
server {
listen 85; #服务访问端口
server_name localhost; #服务名称
location / {
root /opt/erp/nginx/html/dist/; #前端打包的文件放置位置
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
location /jshERP-boot { #后端的访问路径
proxy_pass http://localhost:9999; #代理后端的访问端口
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
6、卸载nginx
停止nginx,删除nginx文件夹即可
7、文件下载
user root;
location /download {
alias /root/server/topboxUpgrade;
autoindex on;
autoindex_exact_size off;
}