nginx 302 301 设置 url 转跳 nginx 资源重定向 nginx tcp 和 http 转发

本文涉及的产品
云服务器 ECS,每月免费额度200元 3个月
云服务器ECS,u1 2核4GB 1个月
简介: nginx 代理后端网站,和 网站资源目录重定向到其他连接地址

#---ssl 301 转跳 ---#   
 if ($server_port = 80){
   
          rewrite ^(/2.php)$ http://www.eisc.cn$1 permanent;
       }
#--- 目录301 转跳 ---#
设置 301 转跳, 
location /ccb/ {
   
    return 301 http://work.eisc.cn;
    proxy_pass http://eisc.cn/cs;
    index  index.html index.htm;
}

#---- 目录 302 转跳 ----#
                location /ruanjian/ {
   
                    rewrite ^(.*)$ http://114.132.64.103:62011/$1 permanent;
                    index  index.html index.htm;
                }

# 说明:讲不带www 转到带www的,需要将不带www 的单独一个server 子站点配置转跳到 https://www
return 301 https://www.eisc.cn$request_uri;

# 设置 302 重定向 
location /ccb/ {
   
    rewrite /ccb/activity(.*)$ https://www.baidu.com break;
    proxy_pass http://192.168.118.14/;
    index  index.html index.htm;
}

#----------------------------   nginx 转发 反向代理 -----------------------------#
 # nginx 子站点tcp转发

            server{
   
                listen 80;
                server_name work.eisc.cn;
                # 当前地址

                location / {
   
                    proxy_pass http://10.1.1.3:62011;
                    # 代理目标地址

                    #---- 记录 IP 地址 ----#
                    #proxy_redirect off;
                    #proxy_set_header Host $http_host;
                    #proxy_set_header X-Real-IP $remote_addr;     
                    #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                }

                location /ruanjian/ {
   
                    rewrite ^(.*)$ http://114.132.64.103:62011/$1 permanent;
                    index  index.html index.htm;
                }
                # 将当前连接地址中的目录 ruanjian 转跳到 302 目标地址 http://114.132.64.103:62011   其中  $1 自动补上后缀地址
            }

#------------- nginx https 转发 -------------#
# 注意如果需要配置ssl 需要再nginx 主配置http 模块文件加入ssl 证书配置,否则子站点无法设置ssl ,将会报错
ssl_certificate    /www/www/ssl/www/eisc.pem; 
ssl_certificate_key    /www/www/ssl/www/eisc.key; 
# 需要已经存在的任意证书文件

#------------- https 站点 ----------#
server{
   
listen 443 ssl;
server_name eisc.cn www.eisc.cn;

#----------------  ssl 证书  ----------------------
ssl_certificate    /www/www/ssl/www/eisc.pem; 
ssl_certificate_key    /www/www/ssl/www/eisc.key; 
    #ssl on;
    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;

    add_header jiedian "eisc.cn-ceshi";
    add_header "开发商"  "小绿叶技术博客eisc.cn";
    add_header "节点"  "小绿叶总站--总部";

location / {
   
     proxy_pass http://eisc.cn;
  }
}
目录
相关文章
|
5天前
|
域名解析 网络协议 开发工具
阿里云DNS常见问题之访问重定向的url访问有问题如何解决
阿里云DNS(Domain Name System)服务是一个高可用和可扩展的云端DNS服务,用于将域名转换为IP地址,从而让用户能够通过域名访问云端资源。以下是一些关于阿里云DNS服务的常见问题合集:
|
4天前
|
监控 Unix 应用服务中间件
Android-音视频学习系列-(八)基于-Nginx-搭建(rtmp、http)直播服务器
Android-音视频学习系列-(八)基于-Nginx-搭建(rtmp、http)直播服务器
|
5天前
|
数据采集 网络协议
WWW(URL,HTTP,HTML)
WWW(URL,HTTP,HTML)
7 1
|
5天前
|
应用服务中间件 Shell nginx
win10 nginx设置开机启动 --亲测有效
win10 nginx设置开机启动 --亲测有效
26 0
|
5天前
|
数据采集 缓存 监控
HTTP与URL基础解析及简单示例实践
HTTP与URL基础解析及简单示例实践
|
5天前
|
前端开发 应用服务中间件 网络安全
http转为https,ssl证书安装及nginx配置
http转为https,ssl证书安装及nginx配置
68 1
|
负载均衡 Unix 应用服务中间件
|
网络协议 应用服务中间件 nginx
|
应用服务中间件 nginx C语言
http://www.vxiaotou.com