1、配置文件模板
[root@local-kvm ~]# grep -vE '^(#|$)' /etc/nginx/nginx.conf |grep -i include
include /usr/share/nginx/modules/*.conf;
include /etc/nginx/mime.types;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/default.d/*.conf;
- conf.d/vm62.conf
[root@local-kvm conf.d]# cat /etc/nginx/conf.d/vm.conf
#include /etc/nginx/conf.d/80.cnf;
server {
listen 80;
server_name 192.168.100.62;
include /etc/nginx/conf.d/80.cnf;
}
- conf.d/80.cnf
location /zabbix/ {
proxy_pass http://192.168.100.62:8080/;
}
# nacos集群版
location /nacos/ {
proxy_pass http://192.168.100.63/nacos/;
}
# nacos单节点版
location /nacos2/ {
proxy_pass http://192.168.100.62:8848/nacos/;
}
2、代理harbor
- server端配置
[root@local-kvm conf.d]# cat server.conf
server {
listen 180;
client_max_body_size 1000m; #避免上传失败
include /etc/nginx/conf.d/180.cnf;
}
[root@local-kvm conf.d]# cat 180.cnf
# harbor
location ^~ /harbor/ {
proxy_pass http://192.168.100.62:180/;
}
location ~* /.*\.(gif|jpg|jpeg|png|bmp|swf)$
{
proxy_pass http://192.168.100.62:180;
}
location ~* /.*\.(js|css)?$
{
proxy_pass http://192.168.100.62:180;
}
location ~* .*$
{
proxy_pass http://192.168.100.62:180;
proxy_set_header Host $host; #避免出现400的问题
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_hide_header X-Powered-By;
}
~
- nginx代理harbor–地址重写
server {
listen 80;
server_name 192.168.137.3;
client_max_body_size 1000m;
location /harbor/ {
rewrite /(.*) http://192.168.137.3:180/;
}
}
3、nginx代理 yum源
- 服务端nginx配置
server {
listen 8082;
server_name localhost;
location / {
autoindex on; #开启目录浏览
root /mnt/cdrom/;
}
}
- 客户端
[local-base]
name=local-base
baseurl=http://10.10.20.10:8082/
enabled=1
gpgcheck=0
4、tengine4层反向代理Mysql
- 检验stream模块是否安装
> */sbin/nginx -V
Tengine version: Tengine/2.3.3
nginx version: nginx/1.18.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/erp/tengine/ --with-stream --with-stream=dynamic --with-stream_ssl_module --with-stream_realip_module
cat nginx.conf
...
load_module /erp/tengine/modules/ngx_stream_module.so; #加载代理模块,要写在配置文件开头
stream {
include lyzm/upstream.cnf;
include lyzm/stream.cnf;
}
cat lyzm/upstream.cnf
upstream mysql {
hash $remote_addr consistent; #通过配置一致性hash来防止调度异常
server 192.168.137.61:3306 weight=5 max_fails=3 fail_timeout=30s;;
}
cat stream.cnf
server {
listen 3306 so_keepalive=on; # 开启tcp存活探针
proxy_connect_timeout 10s; # 连接超时时间
proxy_timeout 300s; # 端口保持时间
proxy_pass mysql;
}
5、nginx代理本地文件
root 和 alias区别
- root
server {
listen 8083;
server_name localhost;
location /dev/ {
root /data/src/page/dev/;
index index.html;
}
}
> curl localhost:8083/dev/index.htm
> 相当于是访问到 /data/src/page/dev/dev/index.html,返回404
- alias
server {
listen 8083;
server_name localhost;
location /dev/ {
alias /data/src/page/dev/;
index index.html;
}
}
> curl localhost:8083/dev/index.html
> 正常访问200
- 其他设置
server {
listen 8099;
server_name "测试文件夹代理服务";
# 配置跨域
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
add_header Access-Control-Allow-Headers Content-Type,Authorization;
location / {
#添加访问日志
access_log 路径/name.log;
#代理的本地文件夹
root ***;
# 开启目录浏览功能;
autoindex on;
#关闭详细文件大小统计,让文件大小显示MB,GB单位,默认为b;
autoindex_exact_size off;
#开启以服务器本地时区显示文件修改日期!
autoindex_localtime on;
}
}
556

被折叠的 条评论
为什么被折叠?



