配置nginx方向代理,实现URL隐形转发

(附带nginx配置文件详解)

免费领取满减阿里云红包
项目名称:【域名解析–隐形URL转发】–centos 7.3
环境:
阿里云服务器之上有多个tomcat;
tomcat的网站基于ip+端口开发+项目名名称。
要求:
访问二级域名http://wanbo.****.cn/跳转至tomcat的web网站,实现隐形URL转发。
方案:
nginx代理tomcat ;
二级域名绑定nginx代理服务器的ip。


实施:
nginx端
安装nginx及其客户端

yum -y install nginx  pcre-devel openssl-devel

修改配置文件
vi /etc/nginx/nginx.conf #server段

# 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/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;events {worker_connections 1024;
}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 2048;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;server {listen       80 default_server;listen       [::]:80 default_server;server_name  wanbo.**.cn;        #二级域名root         /usr/share/nginx/html;# Load configuration files for the default server block.include /etc/nginx/default.d/*.conf;location / {                                                    #该段rewrite ^/ http://$http_host/sdkManager/;                    #}                                                               #location /sdkManager/ {                                         #proxy_pass http://147.93.151.96:8081/sdkManager/;            #该段index index.html index.htm index index.jsp login.jsp;proxy_redirect http://147.93.151.96:18082 http://$http_host;proxy_set_header Cookie $http_cookie;proxy_set_header Remote_Addr $remote_addr;proxy_set_header REMOTE-HOST $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header X-Real-IP $remote_addr;}error_page 404 /404.html;location = /40x.html {}error_page 500 502 503 504 /50x.html;location = /50x.html {}}# Settings for a TLS enabled server.
#
#    server {
#        listen       443 ssl http2 default_server;
#        listen       [::]:443 ssl http2 default_server;
#        server_name  _;
#        root         /usr/share/nginx/html;
#
#        ssl_certificate "/etc/pki/nginx/server.crt";
#        ssl_certificate_key "/etc/pki/nginx/private/server.key";
#        ssl_session_cache shared:SSL:1m;
#        ssl_session_timeout  10m;
#        ssl_ciphers HIGH:!aNULL:!MD5;
#        ssl_prefer_server_ciphers on;
#
#        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf;
#
#        location / {
#        }
#
#        error_page 404 /404.html;
#            location = /40x.html {
#        }
#
#        error_page 500 502 503 504 /50x.html;
#            location = /50x.html {
#        }
#    }}

配置完成ngixn得隐形URL转发后,在域名得dns解析配置中 配置对应得A记录(该服务器得公网ip)

配置文件详解


Nginx配置文件nginx.conf详解nginx配置文件详解:#定义Nginx运行的用户和用户组user www www; #nginx进程数。
worker_processes 8;#全局错误日志定义类型,[ debug | info | notice | warn | error | crit ]
error_log /var/log/nginx/error.log info;#进程文件
pid /var/run/nginx.pid;#一个nginx进程打开的最多文件描述符数目要与ulimit -n的值保持一致。
worker_rlimit_nofile 65535;#工作模式与连接数上限
events
{
#参考事件模型,use [ kqueue | rtsig | epoll | /dev/poll | select | poll ]; epoll模型是Linux 2.6以上版本内核中的高性能网络I/O模型,如果跑在FreeBSD上面,就用kqueue模型。
use epoll;
#单个进程最大连接数(最大连接数=连接数*进程数)
worker_connections 65535;
}#设定http服务器
http
{
include mime.types; #文件扩展名与文件类型映射表
default_type application/octet-stream; #默认文件类型
#charset utf-8; #默认编码
server_names_hash_bucket_size 128; #服务器名字的hash表大小
client_header_buffer_size 32k; #上传文件大小限制
large_client_header_buffers 4 64k; #设定请求缓
client_max_body_size 8m; #设定请求缓
sendfile on; #开启高效文件传输模式,sendfile指令指定nginx是否调用sendfile函数来输出文件,对于普通应用设为 on,如果用来进行下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络I/O处理速度,降低系统的负载。注意:如果图片显示不正常把这个改成off。
autoindex on; #开启目录列表访问,合适下载服务器,默认关闭。
tcp_nopush on; #防止网络阻塞
tcp_nodelay on; #防止网络阻塞
keepalive_timeout 120; #长连接超时时间,单位是秒#FastCGI相关参数是为了改善网站的性能:减少资源占用,提高访问速度。下面参数看字面意思都能理解。
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;#gzip模块设置
gzip on; #开启gzip压缩输出
gzip_min_length 1k; #最小压缩文件大小
gzip_buffers 4 16k; #压缩缓冲区
gzip_http_version 1.0; #压缩版本(默认1.1,前端如果是squid2.5请使用1.0)
gzip_comp_level 2; #压缩等级
gzip_types text/plain application/x-javascript text/css application/xml;
#压缩类型,默认就已经包含text/html,所以下面就不用再写了,写上去也不会有问题,但是会有一个warn。
gzip_vary on;
#limit_zone crawler $binary_remote_addr 10m; #开启限制IP连接数的时候需要使用upstream blog.ha97.com {
#upstream的负载均衡,weight是权重,可以根据机器配置定义权重。weigth参数表示权值,权值越高被分配到的几率越大。
server 192.168.80.121:80 weight=3;
server 192.168.80.122:80 weight=2;
server 192.168.80.123:80 weight=3;
}#虚拟主机的配置
server
{
#监听端口
listen 80;
#域名可以有多个可以用空格隔开
server_name www.junxilinux.com  junxilinux.com;
index index.html index.htm index.php;
root /data/www/junxi;
location ~ .*\.(php|php5)?$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
#图片缓存时间设置
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 10d;
}
#JS和CSS缓存时间设置
location ~ .*\.(js|css)?$
{
expires 1h;
}
#日志格式设定
log_format access ‘$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/junxiaccess.log access;#对 “/” 启用反向代理
location / {
proxy_pass http://127.0.0.1:88;
proxy_redirect off;  关闭代替参数
proxy_set_header X-Real-IP $remote_addr;
#后端的Web服务器可以通过X-Forwarded-For获取用户真实IP
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#以下是一些反向代理的配置,可选。
proxy_set_header Host $host;
client_max_body_size 10m; #允许客户端请求的最大单文件字节数
client_body_buffer_size 128k; #缓冲区代理缓冲用户端请求的最大字节数,
proxy_connect_timeout 90; #nginx跟后端服务器连接超时时间(代理连接超时)
proxy_send_timeout 90; #后端服务器数据回传时间(代理发送超时)
proxy_read_timeout 90; #连接成功后,后端服务器响应时间(代理接收超时)
proxy_buffer_size 4k; #设置代理服务器(nginx)保存用户头信息的缓冲区大小
proxy_buffers 4 32k; #proxy_buffers缓冲区,网页平均在32k以下的设置
proxy_busy_buffers_size 64k; #高负荷下缓冲大小(proxy_buffers*2)
proxy_temp_file_write_size 64k;
#设定缓存文件夹大小,大于这个值,将从upstream服务器传
}#设定查看Nginx状态的地址
location /NginxStatus {
stub_status on;
access_log on;
auth_basic “NginxStatus”;
auth_basic_user_file conf/htpasswd;
#htpasswd文件的内容可以用httpd提供的htpasswd工具来产生。
}#本地动静分离反向代理配置
#所有jsp的页面均交由tomcat或resin处理
location ~ .(jsp|jspx|do)?$ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8080;
}
#所有静态文件由nginx直接读取不经过tomcat或resin
location ~ .*.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$
{ expires 15d; }
location ~ .*.(js|css)?$
{ expires 1h; }

配置nginx方向代理,实现URL隐形转发 (附带nginx配置文件详解)相关推荐

  1. NGINX 安装、启停、平滑升级、配置文件详解

    NGINX安装.启停.平滑升级 一.NGINX 安装 1.下载nginx 2.nginx解压安装 3.预先安装 4.nginx编译 5.安装nginx 6.查看安装路径 7.启动nginx 二.NGI ...

  2. Web集群案例实战 -- Nginx 反向代理根据URL中的目录地址实现代理转发 -- 案例实战

    Nginx 反向代理根据URL中的目录地址实现代理转发 -- 案例实战 前言 一.需求背景 前言 本环境是基于 Centos 7.8 系统构建Nginx学习环境 具体构建,请参考 Nginx-1.18 ...

  3. nginx反向代理替换URL

    系列文章目录 nginx反向代理替换URL 文章目录 系列文章目录 前言 一.location作用 二.直接替换location 匹配部分 前言 nginx 提供反向代理服务,日常开发过程中有时候我们 ...

  4. Nginx(二):反向代理原理 与 配置文件详解

    相关阅读: Nginx(一):Nginx原理概述 与 安装步骤详解 Nginx(二):反向代理原理 与 配置文件详解 Nginx(三):负载均衡策略 与 Nginx静态服务器 Nginx(四):Ngi ...

  5. nginx学习简介-安装-启动-命令-nginx配置文件详解

    nginx是什么:nginx是一个高性能的HTTP和反向代理web服务器.同时也提供了IMAP/POP3/SMTP服务. nginx特点:开源.占内存少.轻量级.高性能(有报告表面nginx能支持高达 ...

  6. nginx服务器安装及配置文件详解

    nginx服务器安装及配置文件详解 seanlook 5月26日 发布 4 推荐 97 收藏,9.2k 浏览 nginx在工作中已经有好几个环境在使用了,每次都是重新去网上扒博客,各种编译配置,今天自 ...

  7. nginx.conf 配置文件详解

    本文来说下nginx.conf 配置文件详解 文章目录 Nginx 配置文件概述 nginx.conf 配置文件 通用(这里是 windows 系统系 nginx1.14.2 下 nginx.conf ...

  8. CENTOS7 高性能Linux集群 通过yum进行 haproxy配置 !安装 !使用!HAProxy配置文件详解

    Haproxy配置 永久修改名字:便于区分虚拟机! Haproxy:hostnamectl set-hostname haproxy Web1: hostnamectl set-hostname WE ...

  9. nginx的配置文件详解

    文章目录 1. nginx的配置文件详解 2. nginx.conf配置详解 3. 用于调试.定位问题的配置参数 4. 正常运行必备的配置参数 5. 优化性能的配置参数 6. 事件相关的配置:even ...

最新文章

  1. 九. Python基础(9)--命名空间, 作用域
  2. 搭建XSS (跨网站指令码) 测试平台
  3. vue element 框架 自定义轮播图,点击上下翻图,并让图片居中
  4. JMETER 各组件执行顺序与作用域
  5. iOS ASI--文件下载
  6. 奈学教育CEO孙玄:成为一个有情怀的工程师,我的12点思考
  7. 简易交通灯设计——数电课设
  8. 推荐几款好用的手机编程APP!
  9. python怎么定义未知数_码如其人,同学你能写一手漂亮的Python函数吗
  10. 全国信息竞赛语言有python吗_2019年全国信息学竞赛有哪些
  11. Oracle数据库----------------索引
  12. 彻底解决文件路径问题
  13. Failed at the react-admin_client@0.1.0 start script、react-app-rewired : command not found
  14. 慕课Java第三季学习及笔记整理
  15. 64位和32位有什么区别?到底哪个更快?——硬核科普
  16. 下载STM32CubeMX软件固件库包的方法
  17. iphone,ipad模拟器截图(小方法)
  18. 基于CBO的执行计划简介
  19. 制作PS合成在易拉罐中洗澡的水果
  20. ACL访问控制列表(详细配置教程)

热门文章

  1. Rabbitmq手动应答代码实现与测试
  2. 美业多门店管理系统,智慧门店数字化方案
  3. 【工程实践】Django系列-Admin站点管理(8)
  4. 【眼动仪】Tobii 卸载问题
  5. 【知识整理】安卓(Android)应用上传360应用市场步骤详解
  6. 间谍软件,恶意软件或垃圾软件如何进入我的计算机?
  7. Jsp网上超市设计与实现(源代码+论文)
  8. 合并果子2之蚂蚁搬沙
  9. 运维--域控服务器--策略
  10. 谷歌浏览器一直遇到崩溃的问题,只需删除一个文件就能解决