请通过浏览器功能收藏网页

nginx根据配置域名反向代理服务 配置文件 NGINX

发布时间:2018-08-07 10:57:53  作者:本站编辑  来源:本站原创  浏览次数:
我有话说 | 分享 |
www.javainfo.com.cn 上干货 欢迎收藏

nginx.conf



#user  nginxu nginxg;

worker_processes  4;


error_log  logs/error.log;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;


pid        logs/nginx.pid;


events {

    worker_connections  10240;

}


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;

#del versioninfo

server_tokens off;


    #keepalive_timeout  0;

    keepalive_timeout  75s 120s;  #two min


    #gzip  on;

     gzip on;

     gzip_min_length 1k;

     gzip_buffers 4 16k;

     gzip_http_version 1.0;

     gzip_comp_level 2;

     gzip_types text/plain application/x-javascript text/css application/xml text/javascript image/jpeg image/gif image/png;

     gzip_vary off;

     gzip_disable "MSIE [1-6]\.";

        #当没有配置的的域名 指向到此服务器的时候, 系统会默认走第一个 域名配置 及 pingbi.tangshan.gov.cn 

        #我们只需要将 其响应时间及等待时间 调整到最小 1s 系统会很快响应 跳转到错误提示界面

#默认屏蔽域名设置

upstream pingbi.tangshan.gov.cn { 

                          server  10.204.2.15:8090;                          

                    } 

server{ 

listen 80; 

server_name pingbi.tangshan.gov.cn; 

#larger the keep alive time for client

large_client_header_buffers 4 16k;

client_max_body_size 300m;

client_body_buffer_size 128k;

proxy_connect_timeout 1s;   #one min

proxy_read_timeout 120s;

proxy_send_timeout 120s;

proxy_buffer_size 64k;

proxy_buffers   4 32k;

proxy_busy_buffers_size 64k;

proxy_temp_file_write_size 64k;

#reject iframe refer within other domains

add_header X-Frame-Options "SAMEORIGIN";

#add error tip 

proxy_intercept_errors on;

error_page 403 404 500 502 503 504 /50x.html;

location = /50x.html{

 root html;

}

location / { 

proxy_pass         http://pingbi.tangshan.gov.cn; 

proxy_set_header   Host             $host; 

proxy_set_header   X-Real-IP        $remote_addr;   

proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for; 

}


#主站域名拦截, 指定到  10.204.2.16 服务器 8080端口

upstream www.javainfo.com.cn { 

                          server  10.204.2.16:8080;                          

                    } 

server{ 

listen 80; 

server_name www.javainfo.com.cn; 

#larger the keep alive time for client

large_client_header_buffers 4 16k;

client_max_body_size 300m;

client_body_buffer_size 128k;

proxy_connect_timeout 60s;   #one min

proxy_read_timeout 120s;

proxy_send_timeout 120s;

proxy_buffer_size 64k;

proxy_buffers   4 32k;

proxy_busy_buffers_size 64k;

proxy_temp_file_write_size 64k;

#reject iframe refer within other domains

add_header X-Frame-Options "SAMEORIGIN";

location / { 

proxy_pass         http://www.javainfo.com.cn; 

proxy_set_header   Host             $host; 

proxy_set_header   X-Real-IP        $remote_addr;   

proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for; 

}

    #反向代理服务 监控服务器的 80端口, 所有的HTTP:80请求都会被 拦截

    server {

        listen       80;

        server_name  localhost;

#reject iframe refer within other domains

add_header X-Frame-Options "SAMEORIGIN";

        #charset koi8-r;


        access_log  logs/host.access.log  main;


        location / {

            root   html;

            index  elleage.html elleage.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;

        }

    }

}


  NGINX的简单配置



如有疑问 请留言 欢迎提供建议

评论已有 0