1、nginx是什么?
①、反向代理服务器 --> tomcat
②、html服务器
正向代理:
方向代理:
负载均衡:系统部署图
二、window版nginx的使用
1、有关conf/nginx.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 - r e m o t e u s e r [ remote_user [ remoteuser[time_local] “$request” ’
'$status b o d y b y t e s s e n t " body_bytes_sent " bodybytessent"http_referer" ’
‘“ h t t p u s e r a g e n t " " http_user_agent" " httpuseragent""http_x_forwarded_for”’;
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
#服务器的集群
upstream tomcat_list { #服务器集群名字
server 127.0.0.1:8080 weight=1; #服务器1 weight是权重的意思,权重越大,分配的概率越大。
#server 172.17.0.4:8080 weight=2; #服务器2 weight是权重的意思,权重越大,分配的概率越大
}
server {
listen 80; #监听80端口,可以改成其他端口
#server_name localhost; #当前服务的域名
server_name www.zking.com; #当前服务的域名(虚拟域名也可以)
root html/crm; #将要访问的网站的根目录,nginx节点会自动继承父节点的配置
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
#该句代码是为解决history路由不能跳转的问题,在vue-router官网有介绍
try_files $uri $uri/ /index.html;
}
location ^~/api/ {
#^~/api/表示匹配前缀是api的请求,proxy_pass的结尾有/, 则会把/api/*后面的路径直接拼接到后面,即移除api
proxy_pass http://tomcat_list/;
}
#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;
}
#}
}
2、将nginx文件解压,点击nginx文件–》选择nginx.exe文件,双击开启
报错:
解决方案:
cmd窗口输入HTTP命令netsh http show servicestate查看,
发现有个共同进程ID:5420
①、打开任务管理器,选择服务,找到PID(进程id)5420对应的服务把它停止就可以了。
②、直接在conf/nginx.conf配置文件中改端口号
成功进入:
三、 vue前端项目打包
1、在前台src/api/action.js文件中定义域名
/**
* 对后台请求的地址的封装,URL格式如下:
* 模块名_实体名_操作
*/
export default {
‘SERVER’: ‘http://www.lv.com/T216_SSH’, //服务器
‘SYSTEM_USER_DOLOGIN’: ‘/vue/userAction_login.action’, //用户登陆
‘SYSTEM_USER_DOREG’: ‘/vue/userAction_reg.action’, //用户注册
‘SYSTEM_MENU_TREE’: ‘/vue/treeNodeAction.action’, //左侧树形菜单加载
‘SYSTEM_ARTICLE_LIST’: ‘/vue/articleAction_list.action’, //文章列表
‘SYSTEM_ARTICLE_ADD’: ‘/vue/articleAction_add.action’, //文章新增
‘SYSTEM_ARTICLE_EDIT’: ‘/vue/articleAction_edit.action’, //文章修改
‘SYSTEM_ARTICLE_DEL’: ‘/vue/articleAction_del.action’, //文章删除
‘SYSTEM_USER_GETASYNCDATA’: ‘/vue/userAction_getAsyncData.action’, //vuex中的异步加载数据
‘getFullPath’: k => { //获得请求的完整地址,用于mockjs测试时使用
return this.SERVER + this[k];
}
}
config/index.js文件:
‘use strict’
// Template version: 1.3.1
// see http://vuejs-templates.github.io/webpack for documentation.
const path = require(‘path’)
module.exports = {
dev: {
// Paths
assetsSubDirectory: ‘static’,
assetsPublicPath: ‘…/…/’,
proxyTable: {},
// Various Dev Server settings
host: ‘localhost’, // can be overwritten by process.env.HOST
port: 8088, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined
autoOpenBrowser: false,
errorOverlay: true,
notifyOnErrors: true,
poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-
/**
* Source Maps
*/
// https://webpack.js.org/configuration/devtool/#development
devtool: ‘cheap-module-eval-source-map’,
// If you have problems debugging vue-files in devtools,
// set this to false - it *may* help
// https://vue-loader.vuejs.org/en/options.html#cachebusting
cacheBusting: true,
cssSourceMap: true
},
build: {
// Template for index.html
index: path.resolve(__dirname, ‘…/dist/index.html’),
// Paths
assetsRoot: path.resolve(__dirname, ‘…/dist’),
assetsSubDirectory: ‘static’,
assetsPublicPath: ‘./’,
/**
* Source Maps
*/
productionSourceMap: true,
// https://webpack.js.org/configuration/devtool/#production
devtool: ‘#source-map’,
// Gzip off by default as many popular static hosts such as
// Surge or Netlify already gzip all static assets for you.
// Before setting to `true`, make sure to:
// npm install --save-dev compression-webpack-plugin
productionGzip: false,
productionGzipExtensions: [‘js’, ‘css’],
// Run the build command with an extra argument to
// View the bundle analyzer report after build finishes:
// `npm run build --report`
// Set to `true` or `false` to always turn it on or off
bundleAnalyzerReport: process.env.npm_config_report
}
}
2、打包项目
打开终端,运行:
npm run build
打包成功新增一个文件夹: 这个文件夹就是打包好的所有项目
双击index呈现界面:
3、将项目发布到Linux服务器上
①、安装nginx
查看是否有nginx:
whereis nginx
未拥有:
安装nginx服务器:
Ⅰ.添加 nginx 官方提供的 yum 源(需要联网且时间较长)
rpm -Uvh http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.14.2-1.el7_4.ngx.x86_64.rpm
Ⅱ、使用 yum 安装 nginx
yum install nginx
Ⅲ、查看nginx版本(yum方式安装nginx,它的安装根目录为/etc/nginx)
rpm -qa | grep nginx
Ⅳ、查看是否已启动
systemctl status nginx
Ⅴ、启动
systemctl start nginx
设计为开机自启:
systemctl enable nginx
Ⅵ、设置防火墙开放 80 端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
Ⅶ、重启防火墙
systemctl restart firewalld
访问成功:
四、nginx发布前端项目
1、进入/usr/share/nginx/html文件编辑
按住i进行编辑,按Esc后输入":wq"进行保存退出:改了个标题
2、将mysql安装包删掉
rm -f mysql*
3、将打包好的项目移入
4、解压
unzip dist.zip
5、新建一个文件夹,将index.html与static移入,删除dist.zip的安装包
最后
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数Java工程师,想要提升技能,往往是自己摸索成长,自己不成体系的自学效果低效漫长且无助。
因此收集整理了一份《2024年Java开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Java开发知识点,不论你是刚入门Android开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门!
如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
log.csdnimg.cn/5fa9a6a6ba1c426a86cec817f4a481a4.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA54ix5Zik5pav5aGU,size_20,color_FFFFFF,t_70,g_se,x_16)
最后
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数Java工程师,想要提升技能,往往是自己摸索成长,自己不成体系的自学效果低效漫长且无助。
因此收集整理了一份《2024年Java开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
[外链图片转存中…(img-RP3tDcZI-1715528040619)]
[外链图片转存中…(img-JAim33nP-1715528040620)]
[外链图片转存中…(img-qVy89e4K-1715528040620)]
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Java开发知识点,不论你是刚入门Android开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门!
如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!