前端项目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 前后端分离配置 分发的更多相关文章

  1. 谈谈渲染,玩玩nginx——前后端分离,转发请求到Tomcat的尝试

    一.谈谈"渲染" 相信好多人都挺听过"渲染"这个词,但不清楚它是什么意思?前端开发以为这是后端的活儿,后端开发以为是前端的事儿,推着推着就不了了之.其实渲染很简 ...

  2. nginx 前后端分离 代理转发,解决跨域问题

    场景 适用于公司有前端,项目采用前后端分离.类似于我们 后端 springboot 提供接口,前端专门写html调用相应的接口,解决跨域问题 配置说明 worker_processes 1; even ...

  3. nginx前后端分离路由配置

    参考链接: https://blog.csdn.net/qq_30021219/article/details/80901199

  4. web 部署专题(九):Nginx 前后端分离中csrf_token 认证的实现

    1. 思路 参考:https://stackoverflow.com/questions/20826201/simple-csrf-protection-using-nginx-alone?r=Sea ...

  5. springboot+vue脚手架使用nginx前后端分离

    1.vue配置 /** * * 相对于该配置的nginx服务器请参考nginx配置文件 * */ module.exports = { // 基本路径 publicPath: '/', // 输出文件 ...

  6. SpringBoot20 集成SpringSecurity02 -> 利用SpringSecurity进行前后端分离的登录验证

    1 SpirngBoot环境搭建 创建一个SpringBoot项目即可,详情参见三少的相关博文 参考博文 -> 点击前往 SpirngBoot项目脚手架 -> 点击前往 2 引入Spirn ...

  7. 前后端分离项目 nginx配置实践

    新项目采用前后端分离的方式开发,前后端代码打算分开部署(同机器且同域名),但打算支持后端依然可访问静态资源. 搜索nginx配置大部分都通过url前缀进行转发来做前后端分离,不适用目前项目. 说明 前 ...

  8. nginx反向代理实现前后端分离&跨域问题

    1.代理和跨域 1.1 正向代理 1)用户希望代理服务器帮助其和要访问服务器之间实现通信,需要: a.用户IP报文的目的IP=代理服务器IP: b.用户报文端口号=代理服务器监听端口号: c.HTTP ...

  9. 使用 Nginx 部署前后端分离项目,解决跨域问题

    前后端分离这个问题其实松哥和大家聊过很多了,上周松哥把自己的两个开源项目部署在服务器上以帮助大家可以快速在线预览(喜大普奔,两个开源的 Spring Boot + Vue 前后端分离项目可以在线体验了 ...

随机推荐

  1. nginx会话保持之sticky模块

    nginx会话保持之nginx-sticky-module模块 在使用负载均衡的时候会遇到会话保持的问题,常用的方法有:1.ip hash,根据客户端的IP,将请求分配到不同的服务器上:2.cooki ...

  2. java之子类继承抽象类,子类构造器调用抽象类构造器问题

    package com.wtd; public abstract class Car { private String name= "car"; public Car(String ...

  3. iOS面试准备之思维导图(转)

    以思维导图的方式对iOS常见的面试题知识点进行梳理复习. 目录 1.UI视图相关面试问题 2.Runtime相关面试问题 3.内存管理相关面试问题 4.Block相关面试问题 5.多线程相关面试问题 ...

  4. Google Web Designer打开白屏问题的解决方案

    Google Web Designer是谷歌出品的一个可视化的  HTML5  网页和广告的设计开发工具  Google Web Designer . 官网地址:https://www.google. ...

  5. ES选主策略

    ES版本5.6.3 1.整个流程的开始,实在node启动后触发的,Node.java中start()方法,通过调用ZenDiscovery.java中的doStart()方法,之后会调用startIn ...

  6. oracle创建定时器详解|interval属性

    定时任务首先先创建定时任务中的存储过程 create or replace procedure pro_jggl as                                          ...

  7. Linux运维学习笔记-角色知识总结

    角色通过UID和GID区分 root:超级管理员,拥有所有权限,UID(0). 普通用户:拥有操作自己家目录下的所有权限,其他文件及目录(/etc./var)只有读的权限,UID(500-65535) ...

  8. .NET/C# 使用反射调用含 ref 或 out 参数的方法

    使用反射,我们可以很容易地在运行时调用一些编译时无法确定的属性.方法等.然而,如果方法的参数中包含 ref 或 out 关键字的时候,又该怎么调用呢? 本文将介绍如何反射调用含 ref 或 out 关 ...

  9. django创建第一个项目helloworld

    环境:centos 7,已安装python 3.6环境 1.安装django并创建django第一个项目 1.1.使用pip安装django# pip install Django或指定安装版本# p ...

  10. JZ2440 裸机驱动 第5章 GPIO接口

    本章目标:     掌握嵌入式开发的步骤:编程.编译.烧写程序.运行     通过GPIO的操作了解软件如何控制硬件 5.1 GPIO硬件介绍     S3C2440A有130个多功能输入/输出口引脚 ...