nginx+tomcat 动静分离 的配置文件

简介:

安装忽略了。以下是nginx的配置文件。 记得修改目录权限为nginx。


user  nginx nginx;
worker_processes auto;
error_log    /var/log/nginx/error.log      crit;
pid           /var/run/nginx.pid;
worker_rlimit_nofile 51200;
events
    {
        use epoll;
        worker_connections 51200;
        multi_accept on;
    }
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"';

        server_names_hash_bucket_size 128;
        client_header_buffer_size 32k;
        large_client_header_buffers 4 32k;
        client_max_body_size 50m;
        sendfile   on;
        tcp_nopush on;
        keepalive_timeout 60;
        tcp_nodelay on;
        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
        fastcgi_buffer_size 64k;
        fastcgi_buffers 4 64k;
        fastcgi_busy_buffers_size 128k;
        fastcgi_temp_file_write_size 256k;

        gzip on;
        gzip_min_length  1k;
        gzip_buffers     4 16k;
        gzip_http_version 1.1;
        gzip_comp_level 2;
        gzip_types     text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss;
        gzip_vary on;
        gzip_proxied   expired no-cache no-store private auth;
        gzip_disable   "MSIE [1-6]\.";

        #limit_conn_zone $binary_remote_addr zone=perip:10m;  容器共使用10M的内存来对于IP传输开销
        ##If enable limit_conn_zone,add "limit_conn perip 10;" to server section. 每个IP使用10个连接,添加在location 里面

        server_tokens off;
        access_log off;

server
    {
        listen 80 default_server;
        #listen [::]:80 default_server ipv6only=on;
        server_name  localhost;

        location / {
            root /usr/local/tomcat/webapps/ROOT;
            index  index.htm index.html index.jsp;
        }

        location ~ \.(jsp|jspx|do)?$ {
            index index.jsp;
            proxy_pass http://192.168.10.51:8080;  #来自jsp请求交给tomcat处理
            proxy_redirect off;
            proxy_set_header Host $host;  #后端的Web服务器可以通过X-Forwarded-For获取用户真实IP
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            client_max_body_size 10m;  #允许客户端请求的最大单文件字节数
            client_body_buffer_size 128k; #缓冲区代理缓冲用户端请求的最大字节数
            proxy_connect_timeout 90;  #nginx跟后端服务器连接超时时间(代理连接超时)
            proxy_read_timeout 90;   #连接成功后,后端服务器响应时间(代理接收超时)
            proxy_buffer_size 4k;    #设置代理服务器(nginx)保存用户头信息的缓冲区大小
            proxy_buffers 6 32k;    #proxy_buffers缓冲区,网页平均在32k以下的话,这样设置
            proxy_busy_buffers_size 64k;#高负荷下缓冲大小(proxy_buffers*2)
            proxy_temp_file_write_size 64k; #设定缓存文件夹大小,大于这个值,将从upstream服务器传
        }

        location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {
            root  /usr/local/tomcat/webapps/ROOT;
            expires 1d;
        }

        location ~ ^/(WEB-INF)/ {
            deny all;  
        }

        error_page   404   /404.html;

        ##PHP

        # Deny access to PHP files in specific directory
        #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

        # location ~ \.php$ {
        #     root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #     fastcgi_param  SCRIPT_FILENAME      $document_root$fastcgi_script_name;
        #    include        fastcgi_params;
        #  }

        #location ~ [^/]\.php(/|$)
        #{
        #   try_files $uri =404;
        #   fastcgi_pass  unix:/tmp/php-cgi.sock;
        #   fastcgi_index index.php;
        #   include fastcgi.conf;
        #}
        # location /nginx_status
        # {
        #    stub_status on;
        #    access_log   off;
        # }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /.well-known {
            allow all;
        }

        location ~ /\.
        {
            deny all;
        }

        access_log    /var/log/nginx/access.log;

    }
}









本文转自 295631788 51CTO博客,原文链接:http://blog.51cto.com/hequan/2046293,如需转载请自行联系原作者
目录
相关文章
|
3天前
|
运维 前端开发 应用服务中间件
LNMP详解(八)——Nginx动静分离实战配置
LNMP详解(八)——Nginx动静分离实战配置
37 0
|
3天前
|
缓存 前端开发 JavaScript
tomcat核心技术+Nginx性能调优技术
而Tomcat的基本配置,每个配置项也基本上对应了Tomcat的组件结构,如果要用一张图来形象展现一下Tomcat组成的话
51 1
|
3天前
|
Java 应用服务中间件 Apache
简介Nginx,Tomcat和 Apache
简介Nginx,Tomcat和 Apache
简介Nginx,Tomcat和 Apache
|
3天前
|
运维 前端开发 应用服务中间件
LNMP详解(八)——Nginx动静分离实战配置
LNMP详解(八)——Nginx动静分离实战配置
23 1
|
3天前
|
关系型数据库 MySQL 应用服务中间件
centos7在线安装jdk1.8+tomcat+mysql8+nginx+docker
现在,你已经成功在CentOS 7上安装了JDK 1.8、Tomcat、MySQL 8、Nginx和Docker。你可以根据需要配置和使用这些服务。请注意,安装和配置这些服务的详细设置取决于你的具体需求。
69 2
|
3天前
|
存储 NoSQL 应用服务中间件
Etcd+Confd实现Nginx配置文件自动管理
Etcd+Confd实现Nginx配置文件自动管理
|
3天前
|
运维 Java 应用服务中间件
Nginx+Tomcat动静分离及Nginx优化(企业案例)
Nginx+Tomcat动静分离及Nginx优化(企业案例)
|
3天前
|
Java 应用服务中间件 PHP
Nginx配置文件解释
Nginx配置文件解释
18 1
|
3天前
|
运维 前端开发 Java
Tomcat详解(八)——Tomcat与Nginx实现动静分离
Tomcat详解(八)——Tomcat与Nginx实现动静分离
22 6
|
3天前
|
运维 应用服务中间件 Linux
LNMP详解(五)——Nginx主配置文件详解
LNMP详解(五)——Nginx主配置文件详解
23 1