nginx代理

nginx代理示例

conf.d文件夹中新增文件xxx.conf

	server {
    listen       82;
    server_name localhost;
    try_files $uri $uri/ /index.html;
    root    /var/local/web/dist;
    client_max_body_size   10m;

    location /api {
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://127.0.0.1:8087/;
    }

}

server {
    listen       80;
    server_name  xxx.cn;
    client_max_body_size   10m;

    location / {
        proxy_pass http://localhost:82;
    }

}

还可以新增yyy.conf

server {
    listen       85;
    server_name localhost;
    try_files $uri $uri/ /index.html;
    root    /var/local/web/search;

    location /together {
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://192.168.0.187:10000/together;
    }

}

server {
    listen       80;
    server_name  yyy.cn;

    location / {
        proxy_pass http://localhost:85;
    }

}

新增文件file.conf

server {
    listen  80;
    server_name     xxxx.cn;
    location / {
        root   /var/local/file;
        index  index.html index.htm;
    }
}

主配置文件nginx.conf

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}


stream {
    server {
        listen 6378;
        proxy_pass 192.168.0.6:6379;
        proxy_socket_keepalive on;
        proxy_timeout 60m;
        proxy_connect_timeout 60s;
    }

}


http {
    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;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 4096;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值