nginx 配置

server {
        listen       80;
        server_name  localhost;php

        #charset koi8-r;css

        #access_log  logs/host.access.log  main;html

        location / {
            root   html;
            index  index.html index.htm;
        }nginx

        #error_page  404              /404.html;web

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }apache

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}tomcat

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


        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/;
        }
        
    }session

#注意: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>  

相關文章
相關標籤/搜索