nginx 是我們 web 開發最常用的工具之一,所以我們需要掌握一些 nginx 的基礎知識!
這里我們來看一下 ngxin 的反向代理
nginx反向代理的三種模式
- 基于IP代理
- 基于域名代理
- 基于埠代理
nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
charset utf-8;
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"';
# log_format main 'remote_addr=$remote_addr:$remote_port, http_x_forwarded_for=$http_x_forwarded_for, proxy_add_x_forwarded_for=$proxy_add_x_forwarded_for ';
access_log logs/access_format.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on
# 原始server
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
}
# 引入自定義的server配置
include aden-proxy-server.conf;
}
aden-proxy-server.conf
########################################################################
# 基于埠代理
########################################################################
server {
listen 81;
server_name localhost;
location / {
proxy_pass http://192.168.0.153:9091;
proxy_redirect default;
}
location = /50x.html {
root html;
}
}
server {
listen 82;
server_name localhost;
location / {
proxy_pass http://git.thextrader.cn;
proxy_redirect default;
}
location = /50x.html {
root html;
}
}
########################################################################
# 基于域名代理 + gitlocal負載均衡
########################################################################
#upstream gitlocal{
# server 192.168.0.153:9091;
# server 192.168.0.154:9091;
# server 192.168.0.155:9091;
#}
#upstream gitbj{
# server git.itplh.cn;
#}
#server {
# listen 80;
# server_name gitlocal.cn;
# location / {
# proxy_pass http://gitlocal;
# proxy_redirect default;
# }
# location = /50x.html {
# root html;
# }
#}
#server {
# listen 80;
# server_name gitbj.cn;
# location / {
# proxy_pass http://gitbj;
# proxy_redirect default;
# }
# location = /50x.html {
# root html;
# }
#}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/3343.html
標籤:其他
