Nginx 前后端分离配置 分发
前端项目VUE 端口8081 , 后端项目JAVA 端口8080
# 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/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;
server_name *.android-pos.cn; # Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf; location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
#Web服务器可以通过X-Forwarded-For获取用户真实IP
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#以上三行,目的是将代理服务器收到的用户的信息传到真实服务器上 if ($host ~ ^(http://)?api\.android-pos\.cn){
proxy_pass http://127.0.0.1:8080;
}
proxy_pass http://127.0.0.1:8081;
} #查看nginx运行的状态
location /ngx_status{
stub_status on;
access_log off;
}
#图片缓存时间
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|svg)$ {
root /opt/tomcat/webapps/ROOT/;
expires 1h;
}
#js, css缓存
location ~ .*\.(js|css)$ {
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8080;
proxy_redirect off;
#proxy_cache cache_one;
proxy_cache_valid 200 302 1h;
proxy_cache_valid 301 1h;
proxy_cache_valid any 1m;
expires 4h;
}
#JS 和 CSS缓存时间
location ~ .*\.(js|css)?$ {
root /opt/tomcat/webapps/ROOT/;
expires 1h;
} error_page 404 /404.html;
location = /40x.html {
} error_page 500 503 504 /50x.html;
location = /50x.html {
} error_page 502 /502.html;
location = /502.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 = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# } }
Nginx 前后端分离配置 分发的更多相关文章
- 谈谈渲染,玩玩nginx——前后端分离,转发请求到Tomcat的尝试
一.谈谈"渲染" 相信好多人都挺听过"渲染"这个词,但不清楚它是什么意思?前端开发以为这是后端的活儿,后端开发以为是前端的事儿,推着推着就不了了之.其实渲染很简 ...
- nginx 前后端分离 代理转发,解决跨域问题
场景 适用于公司有前端,项目采用前后端分离.类似于我们 后端 springboot 提供接口,前端专门写html调用相应的接口,解决跨域问题 配置说明 worker_processes 1; even ...
- nginx前后端分离路由配置
参考链接: https://blog.csdn.net/qq_30021219/article/details/80901199
- web 部署专题(九):Nginx 前后端分离中csrf_token 认证的实现
1. 思路 参考:https://stackoverflow.com/questions/20826201/simple-csrf-protection-using-nginx-alone?r=Sea ...
- springboot+vue脚手架使用nginx前后端分离
1.vue配置 /** * * 相对于该配置的nginx服务器请参考nginx配置文件 * */ module.exports = { // 基本路径 publicPath: '/', // 输出文件 ...
- SpringBoot20 集成SpringSecurity02 -> 利用SpringSecurity进行前后端分离的登录验证
1 SpirngBoot环境搭建 创建一个SpringBoot项目即可,详情参见三少的相关博文 参考博文 -> 点击前往 SpirngBoot项目脚手架 -> 点击前往 2 引入Spirn ...
- 前后端分离项目 nginx配置实践
新项目采用前后端分离的方式开发,前后端代码打算分开部署(同机器且同域名),但打算支持后端依然可访问静态资源. 搜索nginx配置大部分都通过url前缀进行转发来做前后端分离,不适用目前项目. 说明 前 ...
- nginx反向代理实现前后端分离&跨域问题
1.代理和跨域 1.1 正向代理 1)用户希望代理服务器帮助其和要访问服务器之间实现通信,需要: a.用户IP报文的目的IP=代理服务器IP: b.用户报文端口号=代理服务器监听端口号: c.HTTP ...
- 使用 Nginx 部署前后端分离项目,解决跨域问题
前后端分离这个问题其实松哥和大家聊过很多了,上周松哥把自己的两个开源项目部署在服务器上以帮助大家可以快速在线预览(喜大普奔,两个开源的 Spring Boot + Vue 前后端分离项目可以在线体验了 ...
随机推荐
- HDU 5586 简单最大子段和变形
Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submiss ...
- 个人知识管理系统Version1.0开发记录(04)
demo model 我们采用mvc软件架构模式,方便以后用Struts2框架技术优化.重构.封装.这次主要设计一些常用的方法工具,即数据访问逻辑.工具:eclipse.oracle.sqldevel ...
- 从0开始springboot
http://412887952-qq-com.iteye.com/blog/2291500
- Sonar在ant工程中读取单元测试和覆盖率报告
虽然sonar支持ant工程的构建,但目前最大的不足是无法在分析过程中产生单元测试和覆盖率报告,这样在sonar面板上覆盖率板块就始终没有数据.但幸运的是,sonar可以读取已经生成好的报告,让报告的 ...
- Linux下各文件夹的含义和用途
Linux根目录”/“下各个系统文件夹的含义和用途 1./boot 该目录默认下存放的是Linux的启动文件和内核. 2./initrd 它的英文含义是boot loader initialized ...
- java并发编程之二--CountDownLatch的使用
CountDownLatch类 允许一个或多个线程等待直到在其他线程中执行的一组操作完成的同步辅助. CountDownLatch能够使一个线程在等待另外一些线程完成各自工作之后,再继续执行.使用一个 ...
- [置顶]
Android 打包apk无敌报错
前言: 这个问题从昨天上午一直到现在,请教了很多大佬,都没有给出确定的解决方案,可能他们也没碰到过可能,不过还是挺感谢他们的建议,一直到今天中午午休,我一直都在想这个问题,就是下面的这个,看了国内很多 ...
- OutOfMemoryError系列(1): Java heap space
每个Java程序都只能使用一定量的内存, 这种限制是由JVM的启动参数决定的.而更复杂的情况在于, Java程序的内存分为两部分: 堆内存(Heap space)和 永久代(Permanent Gen ...
- RF/GBDT/XGBoost/LightGBM简单总结(完结)
这四种都是非常流行的集成学习(Ensemble Learning)方式,在本文简单总结一下它们的原理和使用方法. Random Forest(随机森林): 随机森林属于Bagging,也就是有放回抽样 ...
- Codeforces 1009D:Relatively Prime Graph
D. Relatively Prime Graph time limit per test 2 seconds memory limit per test 256 megabytes input st ...