码迷,mamicode.com
首页 > 其他好文 > 详细

nginx实例

时间:2021-03-01 13:32:37      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:methods   post   abc   head   ken   log   put   logo   get   

1. 域名代理实例:

#user  nobody;
user root;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

pid        /var/run/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;

    sendfile       on;
 
    tcp_nopush     on;
 
    tcp_nodelay    on;
 
    keepalive_timeout  100;         
 
    fastcgi_connect_timeout 6000;
 
    fastcgi_send_timeout 6000;
 
    fastcgi_read_timeout 6000;
 
    fastcgi_buffer_size 256k;
 
    fastcgi_buffers 8 256k;
 
    fastcgi_busy_buffers_size 256k;
 
    fastcgi_temp_file_write_size 256k;
 

 
    client_header_timeout 120s;        
 
    client_body_timeout 120s;          
 
    client_max_body_size 100m;         
 
    client_body_buffer_size 256k;   
 
 
 
    server_names_hash_max_size 512;
 
    server_names_hash_bucket_size 128;
 
 
 
    gzip  on;
 
    gzip_min_length  1k;
 
    gzip_buffers     4 16k;
 
    gzip_http_version 1.1;
 
    gzip_comp_level 9;
 
    gzip_types       text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php;
 
    gzip_vary on;


    server {
        listen       80;
        server_name  www.xxitx.com;

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

        location ^~ /test1/ {
            add_header ‘Access-Control-Allow-Origin‘ *;
            add_header ‘Access-Control-Allow-Credentials‘ ‘true‘;
            add_header ‘Access-Control-Allow-Methods‘ ‘GET,POST,OPTIONS‘;
            proxy_pass http://localhost:8801/;
            proxy_set_header   X-Real-IP         $remote_addr;
            proxy_set_header   Host              $http_host;
            proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

    server {
        listen 443 ssl;
        server_name  www.xxitx.com;
        
        ssl_certificate      cert/3786272_www.yuming.com.pem;
        ssl_certificate_key  cert/3786272_www.yuming.com.key;
 
        ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;  #使用此加密套件。
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;   #使用该协议进行配置。
        ssl_prefer_server_ciphers on;   

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

        location /logo {
	    proxy_pass http://localhost:8088/;
        }

        location ^~ /abc/ {
            add_header ‘Access-Control-Allow-Origin‘ *;
            add_header ‘Access-Control-Allow-Credentials‘ ‘true‘;
            add_header ‘Access-Control-Allow-Methods‘ ‘GET,POST,OPTIONS‘;
            proxy_pass http://192.168.106.1:10080/abc/;
            set $Real $proxy_add_x_forwarded_for;
            if ( $Real ~ (\d+)\.(\d+)\.(\d+)\.(\d+),(.*) ){
                set $Real $1.$2.$3.$4;
            }
        }


    }
    include conf.d/*.conf;
}

 

2. 实例2:

 

#vi /usr/local/nginx/conf/nginx.con

user root;
worker_processes 16;

error_log /var/log/nginx/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;


events {
    worker_connections 1024;
}



http {
    #vhost_traffic_status_zone;
    #vhost_traffic_status_filter_by_host on;
    include /etc/nginx/conf.d/*.conf;
    include mime.types;
    send_timeout 60s;
    default_type  application/octet-stream;
    client_max_body_size 3000M;
    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  /var/log/nginx/access.log  main;
    sendfile        on;
    #keepalive_timeout  65;
   # add_header Access-Control-Allow-Origin *;
    add_header Access-Control-Allow-Headers X-Requested-With;
    add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
     # client_max_body_size 200m;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;
    limit_conn_zone $binary_remote_addr zone=perip:10m; #限制单个ip的session存储上限
    limit_conn perip 10; #限制单个ip的并发连接数
    limit_rate 1024k;

    #client_max_body_size    200m;
    client_body_buffer_size  128k;
    client_header_timeout 15;
    client_body_timeout 15;
    proxy_connect_timeout    600;
    proxy_read_timeout      600;
    proxy_send_timeout      6000;
    proxy_buffer_size        16k;
    proxy_buffers            4 64k;
    proxy_busy_buffers_size 64k;
    proxy_temp_file_write_size 64k;

    gzip  on;           #打开gzip压缩功能
    gzip_min_length 1k; #压缩阈值
    gzip_buffers 4 16k; #buffer 不用修改
    gzip_comp_level 2;  #压缩级别:1-10,数字越大压缩的越好,时间也越长
    gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;


    map $http_upgrade $connection_upgrade {
        default upgrade;
        ‘‘ close;
    }

}

 

#vi /etc/nginx/conf.d/*.conf

server {
        
        listen 10080;
        client_max_body_size 3000M;
        server_name 135.211.1.1 www.for.example.com;

        root /home/wwwroot/default;
        location ~^/abc/getinfo {
            proxy_pass http://localhost:8006;
            proxy_http_version 1.1;
            proxy_set_header Host 135.211.1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_hide_header X-Frame-Options;
            #proxy_set_header Host $host;
            proxy_set_header x-forwarded-for  http://135.211.1.1:8006/;

            if ( $request_method = ‘OPTIONS‘ ) {
            add_header Access-Control-Allow-Origin $http_origin;
            add_header Access-Control-Allow-Headers Authorization,Content-Type,Accept,Origin,User-Agent,DNT,Cache-Control,X-Mx-ReqToken,X-Data-Type,X-Requested-With;
            add_header Access-Control-Allow-Methods GET,POST,OPTIONS,HEAD,PUT;
            add_header Access-Control-Allow-Credentials true;
            add_header Access-Control-Allow-Headers X-Data-Type,X-Auth-Token;
            return 200;
        }

        }

        
        location ~^/abc/#/home {
            root /home/wwwroot/default;
        }


    }

 

nginx实例

标签:methods   post   abc   head   ken   log   put   logo   get   

原文地址:https://www.cnblogs.com/good2study/p/14458441.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!