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 前后端分离项目可以在线体验了 ...
随机推荐
- mfc "缺少函数标题(是否是老式的形式表)"的总结
首先出现这种问题要定位到程序中出错的地方查看,如果没有问题就仔细看类的声明和定义.可能是对应类的后面没有加: 第二个原因是可能忘记了添加头文件 "stdafx",如果是这样可以加上 ...
- HDU1598 并查集+贪心
find the most comfortable road Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- 基于Oracle的SQL优化(崔华著)-整理笔记-第5章“Oracle里的统计信息”
第5章“Oracle里的统计信息” 详细介绍了Oracle数据库里与统计信息相关的各个方面的内容,包括 Oracle数据库中各种统计信息的分类.含义.收集和查看方法,以及如何在Oracle数据库里正确 ...
- hdu5618
题解: CDQ分治 三重分治 第一重排序 第二重CDQ 第三重树状数组 代码: #include<cstdio> #include<cmath> #include<cst ...
- 进程间通信IPC
body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...
- linux提权辅助工具(二):linux-exploit-suggester-2.pl
来自:https://github.com/jondonas/linux-exploit-suggester-2/blob/master/linux-exploit-suggester-2.pl #! ...
- 是用TOP关键字对COUNT性能优化
在对大数据量进行检索或者分页的时候需要计算命中记录数大小,一般情况下我们可以直接COUNT得到结果,但是当结果集很大的时候(比如1万以上)具体结果值已经不重要了.没有人真的翻阅1万条记录,比如百度,你 ...
- ASP.NET MVC 使用NPOI导出Excel 无法访问已关闭的流(转)
第一步重写MemoryStream , 让它不能自动关闭. //新建类 重写Npoi流方法 public class NpoiMemoryStream : MemoryStream { public ...
- Python PIL : IOError: decoder jpeg not available
The first thing I check when I got this error was to check if libjpeg was installed. Lets try this s ...
- 优先队列底层实现是堆(heap)(操作系统进程调度)
只有一个CPU的情况下,比如作业系统中的调度程序,当一个作业完成后,需要在所有等待调度的作业中选择一个优先级最高的作业来执行(删除),并且也可以添加一个新的作业到作业的优先队列中(插入). 插入操作 ...