配置动静分离的时候遇到了一些问题,一个是配置nginx配置文件有问题导致访问不到服务器,另一个问题是配置静态资源的路径和实际的资源目录不匹配导致404,502等错误

结合上一篇的基础,在此将动静分离的配置文件主要部分做一说明,为日后参考。

 #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; # ******************* step one ****************
upstream tomcats {
server 192.168.248.130:8080 weight=3;
server 192.168.248.132:8080 weight=1;
} #gzip on; server {
listen 80;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location ~.(gif|jpg|jpeg|png|bmp|swf|css|js)$ {
root /usr/local/nginx/html;
} location ~ .*\.(html|jsp|do|action)$ { #动态
proxy_pass http://tomcats;
root html;
index index.html index.htm;
} #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;
# }
#} }

点击查看 nginx配置文件

静态资源目录说明

如果工程名字叫做hello,则访问hello项目的静态资源,需要在nginx的静态资源配置目录下面放置相应的工程名文件夹

Nginx+Tomcat配置负载均衡-动静分离(二)的更多相关文章

  1. 简单的 Nginx+Tomcat 配置负载均衡集群

    简单 Nginx+Tomcat 配置负载均衡集群 前期准备 解压两个tomcat,修改端口号 server1:8081 server:8082 同时启动 nginx官网下载解压版nginx 创建一个简 ...

  2. Nginx+Tomcat 配置负载均衡集群

    一.Hello world 1.前期环境准备 准备两个解压版tomcat,如何同时启动两个tomcat,请看我的另一篇文章<一台机器同时启动多个tomcat>. nginx官网下载解压版n ...

  3. Nginx+Tomcat配置负载均衡(一)

    关于负载均衡原理方面的知识点不在本文讨论范畴,本文主要就负载均衡配置过程中的细节部分配置做详细说明. 本次负载均衡大致的配置如下: 环境 : WIN7 + VM虚拟机3台(centos6.5) Ngi ...

  4. nginx+tomcat 配置负载均衡集群 (转载)

    一.Hello world 1.前期环境准备 准备两个解压版tomcat,如何同时启动两个tomcat,请看我的另一篇文章<一台机器同时启动多个tomcat>. nginx官网下载解压版n ...

  5. Nginx + Tomcat 配置负载均衡集群简单实例

    一.Hello world 1.前期环境准备 准备两个解压版tomcat,如何同时启动两个tomcat,请看我的另一篇文章<一台机器同时启动多个tomcat>. nginx官网下载解压版n ...

  6. 从零开始学 Java - CentOS 下 Nginx + Tomcat 配置负载均衡

    为什么现在有非常多的聪明人都在致力于互联网? 最近在读埃隆·马斯克传记,他说「我认为现在有非常多的聪明人都在致力于互联网」. 仔细一想,好像真的是这样的. 我问了自己一个问题:如果你不敲代码了,你能做 ...

  7. nginx + tomcat配置负载均衡

    目标:Nginx做为HttpServer,连接多个tomcat应用实例,进行负载均衡. 注:本例程以一台机器为例子,即同一台机器上装一个nginx和2个Tomcat且安装了JDK1.7. 1.安装Ng ...

  8. Nginx--Windows环境下Nginx+tomcat配置(包括动静分离)

    前提条件: (1)已安装好tomcat,且能成功启动 (2)已安装好Nginx,且能成功启动 接下来进行配置: (1)在Nginx的conf文件夹中新增两个文件,分别如下:(新建文件后,直接复制代码即 ...

  9. Windows下使用Nginx+tomcat配置负载均衡

    Nginx是一款轻量级的Web服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行.由俄罗斯的程序设计师Igor Sysoev所开发,供俄国大型的入口 ...

随机推荐

  1. restore not found的错误(问题2)

    最近在写gan,那么就牵扯到在一个session中加载两个图,restore的时候会有问题.如这篇文章写的(http://blog.csdn.net/u014659656/article/detail ...

  2. Spring Boot Application

    spring boot默认已经配置了很多环境变量,例如,tomcat的默认端口是8080,项目的contextpath是“/”等等,spring boot允许你自定义一个application.pro ...

  3. redis 持久化共享 Session

    https://docs.microsoft.com/zh-cn/azure/redis-cache/cache-aspnet-session-state-provider

  4. mybatis的配置与使用

    mybatis的配置与使用 一.全局配置文件配置 properties标签 Properties标签可以用来加载配置文件.例如,我们可以将数据库的连接信息放入到一个配置文件(db.properties ...

  5. java中线程的三种实现方式

    一下记录下线程的3中实现方式:Thread,Runnable,Callable 不需要返回值时,建议使用Runnable:有返回值时建议使用Callable 代码如下所示: package com.f ...

  6. colormap中的内嵌彩色模块和调用方式

    内嵌彩色模块代码: import numpy as npimport matplotlib.pyplot as plt # Have colormaps separated into categori ...

  7. 开发部署项目时出现:java.lang.OutOfMemoryError: PermGen space

    java.lang.OutOfMemoryError: PermGen space 错误: 原文地址:http://www.cnblogs.com/shihujiang/archive/2012/06 ...

  8. Go项目中beego的orm使用和gorm的使用

    按照beego官方文档练习ORM的使用,model创建完始终没找到办法创建表,于是使用gorm翻译文档和官方文档进行了练习,使用起来还是比较简单. 安装: 方法一:Terminal打开,go get ...

  9. C#中自定义高精度Timer定时器的实例教程

    Timer 用于以用户定义的事件间隔触发事件.Windows 计时器是为单线程环境设计的,其中,UI 线程用于执行处理.它要求用户代码有一个可用的 UI 消息泵,而且总是在同一个线程中操作,或者将调用 ...

  10. 使用Python统计函数绘制复杂图形matplotlib

    一.堆积图 1.堆积柱状图 如果将函数bar()中的参数bottom的取值设定为列表y.列表y1代表另一个数,函数bar(x,y1,bottom=y,color="r")就会输出堆 ...