目 录CONTENT

文章目录

nginx配置反向代理以及适配多端

恪晨
2020-05-18 / 0 评论 / 0 点赞 / 288 阅读 / 1 字 / 正在检测是否收录...
温馨提示:
慢慢看,慢慢读,不行就边听歌边读

配置反向代理

server {
  listen 80;
  server_name www.wangboweb.com;
  location / {
    # 显示文件目录而不是解析文件
    autoindex on;
    # 代理到百度
  	proxy_pass http://www.baidu.com;
  }
}

或者

http {
  # 代理多个机器
  upstream local {
  	server 192.168.123.11:80;
    server 192.168.123.12:80;
  }
  # 设置缓存文件路径,缓存名称为myCache
  proxy_cache_path /tmp/nginxCache levels=1:2 keys_zone=myCache:10m max_size=10g inactive=60m use_temp_path=off;
  server {
    # 缓存路径设置
    proxy_cache myCache;
	# 缓存key
    proxy_cache_key $host$uri$is_args$args;
    # 哪些请求不缓存,设置缓存时间为1天
    proxy_cache_valid 200 304 302 1d;
  	proxy_pass http://local;
  }
}

配置适配多端

server {
	listen 80 default_server;
	server_name default_server;
	location / {
		root /var/www/pc;
		if ($http_user_agent ~* 'Android|WebOS|iPhone|iPod|BlackBerry') {
			root /var/www/mobile;
		}
		index index.html;
	}
}

反向代理404问题

server {
  listen 80;
  listen [::]:80;
  listen 443 ssl;
  listen [::]:443 ssl;
  server_name blog.wangboweb.site;
  client_max_body_size 1024m;
  ssl_certificate /etc/nginx/conf.d/blog/blog.pem;
  ssl_certificate_key /etc/nginx/conf.d/blog/blogKey.pem;
  location / {
    proxy_pass https://nas.wangboweb.site:9201/;
    # proxy_set_header HOST $host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }
}
0
博主关闭了当前页面的评论