nginx 反向代理简单实例

本文详细介绍了Nginx服务器的配置方法,包括如何设置代理转发、静态资源缓存及超时时间等。通过实例展示了如何区分配置不同端口的服务,并实现了特定路径请求的转发。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

admin.conf:

upstream local{

    server localhost:19003 weight=1; #本地服务器

}

server{

    listen 19001 default_server;

    server_name 127.0.0.1;

    access_log  /root/logs/nginx/admin.kaoke.me.access.log;

    error_log  /root/logs/nginx/admin.kaoke.me.error.log;

    location /{

        uwsgi_pass 127.0.0.1:19000;

        include /usr/local/etc/nginx/uwsgi_params;

        client_max_body_size 100m;

        uwsgi_connect_timeout 70s;

        uwsgi_send_timeout 1000s;

        uwsgi_read_timeout 180s;

 

        }

     location ~^/static/{

         root /Users/self/git/liantong-web-static/web_statics/admin.kaoke.me;

         expires 1d;

         }

     location ~^/smedia/{

         root /;

         expires 1d;

         }

     location /iapi/ {#loaction 匹配127.0.0.1:19001中的地址是否有/iapi/开头的如果有这个地址转到127.0.0.1:19003

            #DemoBackend1后面的斜杠是一个关键,没有斜杠的话就会传递service到后端节点导致404

            proxy_pass      http://local/;

            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;

    }

 

    }

www.conf:

server {

    listen 19003 default_server;

    server_name 127.0.0.1;

    location /{

        uwsgi_pass 127.0.0.1:19002;

        include /usr/local/etc/nginx/uwsgi_params;

        client_max_body_size 100m;

        uwsgi_connect_timeout 70s;

        uwsgi_send_timeout 1000s;

        uwsgi_read_timeout 180s;

    }

    location ~^/static/{

        root /Users/self/git/liantong-web-static/web_statics/www.kaoke.me;

        expires 1d;

    }

 

#     location ~^/download/ {

#         root /smedia/app/sdasw;

#         expires 1d;

#     }

}

 

转载于:https://my.oschina.net/u/2603728/blog/805216

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值