我们一般是在linux上部署项目,但是公司内测试的linux服务器被征用,测试人员又要登录系统测试。我们的研发网络测试人员无法ping 通(他没有权限连接研发网络)。我想了一下,我的办公电脑和他在同一个网络,之前又安装了jdk8,redis开发环境,故灵机一动,就在办公环境暂时部署了。
基础环境:
windows
jdk8并配置系统变量
redis(看你系统需不需要)
nginx
后端jar包文件
前端文件等
在此说明一下,我的后端是jar包,如果你的是class文件,可以放tomcat运行,比jar运行简单。且我的项目是前后端分离的,也就是说前后端都要nginx配置好。
步骤:
- 1.将后端和前端文件分别放在E盘 data文件夹下
后端结构:E:\data\service\XXXX.jar
前端结构:E:\data\vue\fils-m\index.html
- 2.配置nginx的conf文件
前端转发:
location / {
root E:\data\vue\fils-m;
index index.html index.htm;
}
后端转发
location /fils-m {
index index.html index.htm;
proxy_pass http://127.0.0.1:8083;
proxy_redirect http:// $scheme://;
proxy_connect_timeout 100000;
proxy_send_timeout 100000;
proxy_read_timeout 100000;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host:$server_port;
proxy_redirect http:// $scheme://;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 100m;
}
整体配置:
#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 100;
server_name localhost;
location / {
root E:\data\vue\fils-m;
index index.html index.htm;
}
location /fils-m {
index index.html index.htm;
proxy_pass http://127.0.0.1:8083;
proxy_redirect http:// $scheme://;
proxy_connect_timeout 100000;
proxy_send_timeout 100000;
proxy_read_timeout 100000;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host:$server_port;
proxy_redirect http:// $scheme://;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 100m;
}
#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;
# }
#}
}
- 3.启动后端jar包,特别注意:windows上的编码是GBK,如果直接jar包启动很可能会出现中文乱码,解决办法以utf-8编码启动jar包。
cd 到E盘目录
E:/data/service java -Dfile.encoding=utf-8 -jar fils.jar
回车后启动后端,没有报错,就启动成功了,窗体不要关闭!!!
- 4.启动nginx,这个就不赘述了。
浏览器访问页面和后端,看项目是否启动成功
http://localhost:100/
- 5.完成,吃午饭去!