nginx 配置

server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            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;
        #}


        location /overseas-backend-web {
            proxy_set_header X-Forwarded-Host $host;
            proxy_set_header X-Forwarded-Server $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://127.0.0.1:8080/overseas-backend-web/;
        }
        
        location /overseas-backend-web2 {
            proxy_set_header X-Forwarded-Host $host;
            proxy_set_header X-Forwarded-Server $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://127.0.0.1:8180/overseas-backend-web2/;
        }
        
    }

#注意:overseas-backend-web 和 overseas-backend-web2 是不同项目工程名;

      这样配置有一个不好的地方:对于静态资源也经过nginx转发到了应用服务器(如tomcat),一般情况我们是将对静态资源的访问,只经过nginx,不经过应用服务器(如tomcat)

 

##############################################################

如下配置是 配置不同server_name(即:不同ip或者不同域名)的转发情况

##############################################################

server {
    listen 80;
    server_name  xingyi.ezoutwork.com;

    root   /alidata/www/xingyi;
    index  index.html;

    location /xingyi-frontend-web {
        proxy_pass  http://120.24.77.184:9280/xingyi-frontend-web;

        #Proxy Settings
        proxy_redirect     off;
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
        proxy_max_temp_file_size 0;
        proxy_connect_timeout      90;
        proxy_send_timeout         90;
        proxy_read_timeout         90;
        proxy_buffer_size          4k;
        proxy_buffers              4 32k;
        proxy_busy_buffers_size    64k;
        proxy_temp_file_write_size 64k;
    }

     location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            root /home/tomcat/80.apache-tomcat-8.0.26/webapps/yunlong-backend-web/;
            expires 30d;
        }
 
        location ~ .*\.(js|css)?$
       {
            root /home/tomcat/80.apache-tomcat-8.0.26/webapps/yunlong-backend-web/;
            expires 24h;
        }

 

 

    log_format xingyi_domain '$remote_addr - $cookie_jsessionid:$cookie_member_user:$cookie_manager_user [$time_local] '
                                              '"$request" $status $body_bytes_sent '
                                              '"$http_referer" "$http_user_agent"';
    access_log /alidata/log/nginx/access/xingyi_domain.log xingyi_domain;
}

 

 

 

########################################################

tomcat 默认访问某一个项目配置:

########################################################

        <Context 
             path="/" 
             docBase="/home/tomcat/95.overseas-apache-tomcat-8.0.26/webapps/overseas-backend-web/" 
             debug="0"/> 

 

########################################################

最终方案如下:

########################################################

## Basic reverse proxy server ##
## Apache backend for www.quancha.cn ##

## Start aussitown ##
server {
    listen 80;
    server_name mobile.aussitown.com;

    root   /home/tomcat/95.overseas-apache-tomcat-8.0.26/webapps_static_frontend/;
    index  index.html;

    location /overseas-frontend-web/{
        proxy_pass  http://127.0.0.1:9580/overseas-frontend-web/;

        #Proxy Settings
        proxy_redirect     off;
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
        proxy_max_temp_file_size 0;
        proxy_connect_timeout      90;
        proxy_send_timeout         90;
        proxy_read_timeout         90;
        proxy_buffer_size          4k;
        proxy_buffers              4 32k;
        proxy_busy_buffers_size    64k;
        proxy_temp_file_write_size 64k;
    }

 

    location ~ .*\.(js|css)?$
    {
    root /alidata/server/tomcat/94.alliance-tomcat-8.0.26/webapps/;
        expires 24h;
    }    


    log_format overseas-wechat '$remote_addr - $cookie_jsessionid:$cookie_member_user:$cookie_manager_user [$time_local] '
                            '"$request" $status $body_bytes_sent '
                            '"$http_referer" "$http_user_agent"';

    access_log /alidata/log/nginx/access/overseas-wechat.log overseas-wechat;
}

#######################################

以下是  /home/tomcat/95.overseas-apache-tomcat-8.0.26/webapps_static_frontend/  下的index.html

#######################################

<html><head>
<meta http-equiv="refresh" content="0;url=/overseas-frontend-web">
</head></html>
 

 

 

 

转载于:https://my.oschina.net/u/2605948/blog/726760

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值