[玩转nginx] nginx实现简单的静态服务器

2018-07-17  本文已影响0人  枫叶_huazhe

使用nginx搭建简单的静态web服务器

server {
    listen 9999;
    server_name localhost;

    location / {
      root /var/data/static/starts;
      autoindex on;
      autoindex_exact_size off;
      autoindex_localtime on;
    }

}

参数说明:

跳转错误

server {
    listen 8001;
    server_name 127.0.0.1;
    access_log /var/log/nginx/test_access.log  main;
    proxy_set_header Host             $host;
    proxy_set_header X-Real-IP        $remote_addr;
    proxy_connect_timeout 600;
    proxy_read_timeout 600;
    proxy_send_timeout 600;
    proxy_set_header X-Forwarded-For $http_x_forwarded_for;
    client_max_body_size 20m;

    location / {
    root /etc/nginx/html/store_app/dist/;
    index index.html;
    }

    location /dapeng/ {
        proxy_pass http://10.10.10.48:8989/;
    }

    location /bigdata/ {
        proxy_pass http://superdz.today36524.com/;
    }

    location /biservice/ {
        proxy_pass http://biservice.today36524.com/;
    }

    location ^~ /interface/ {
        rewrite ^/interface/(.*)$ http://biservice.today36524.com/bigData/$1 permanent;
#       proxy_pass http://biservice.today36524.com/bigData/;
    }

    error_log /var/log/nginx/t-mini-8085-8485.log;
    access_log /var/log/nginx/t-mini-8085-8485.log;
}

重写 url跳转

需求http://dalao.com/api/supplier_download/excel/excelDownload.html?fileType=someImport跳转到
http://192.168.10.101/api/excel/excelDownload.html?fileType=someImport

server {
    listen 80;
    server_name dalao.com;
   
    access_log  /var/log/nginx/dalao-com.log;
    error_log /var/log/nginx/dalao-com-error.log;
   
    location /api/supplier_download/ {
   
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        rewrite /api/supplier_download/(.*) http://eywa.sandbox5.today.cn/api/$1 permanen
    }

    location / {
        #Proxy Settings
        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_pass  http://192.168.10.101:8989;
    }
}

nginx正则配置

~ 为区分大小写匹配(可用正则表达式)
!~为区分大小写不匹配
~* 为不区分大小写匹配(可用正则表达式)
!~*为不区分大小写不匹配
^~ 如果把这个前缀用于一个常规字符串,那么告诉nginx 如果路径匹配那么不测试正则表达式。
上一篇下一篇

猜你喜欢

热点阅读