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;
}