初学Nginx(二)静态文件实现按文件夹分离

来源:互联网 发布:一部讲人工智能的电影 编辑:程序博客网 时间:2024/05/29 07:11

nginx路径 D:\nginx-1.12.1  更改端口为8081

tomcat 路径 D:\nginx-1.12.1\apache-tomcat-7.0.70

tomcat根目录 D:\nginx-1.12.1\apache-tomcat-7.0.70\webapps\ROOT

nginx.conf



#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;


    #gzip  on;


upstream localhost {
    #ip_hash;  
    server localhost:8081;  
    #server localhost:8023;  #可配置多个端口
}

    server {
        listen       80;
        server_name  localhost;
#设定访问静态文件直接读取不经过tomcat
location ~ .*\.(jpg|jpeg|png|bmp|swf)$ 
{
root D:\static\jpg;
}


location ~ .*\.(gif)?$
{
root D:\static\gif;



location / {  
proxy_connect_timeout   3;  
proxy_send_timeout      30;  
proxy_read_timeout      30;  
proxy_pass http://localhost;  
}
    }

server {
        listen       8023;
        server_name  localhost;
        location / {
            proxy_pass https://user.qzone.qq.com/398902904/;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }





    # 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;
    #    }
    #}


}


http://localhost:8081/time.gif跟http://localhost/time.gif访问是一样的

原创粉丝点击