动态 版块 发帖 消息 我的
Loading...
小绿叶技术博客
小绿叶技术博客
小绿叶技术Lv149   
nginx 301转跳,资源重定向:转发 反向解析代理,访问目的网站     

#------ 301 转跳 ----#

# 301 访问2.php文件转跳到另一个网站的2.php文件, 删除$1 就不指定文件名,  如果是https 方式 就要将80改为443

在nginx配置文件的  server()  板块进行添加


    if ($server_port = 80){

          rewrite ^(/2.php)$ http://www.eisc.cn$1 permanent;

       }



#----  nginx 转发 反向解析代理--#

 # nginx 子站点tcp转发


server{

listen 80;

listen 443;


server_name www.kbash.cn;


location / {

     proxy_pass http://47.105.46.67;

     index index.php index.html;

  }

}


nginx -s reload        # 重载nginx配置




#-------------------------等待研究--------------------------------------#

#PROXY-START/

location  ~* \.(gif|png|jpg|css|js|woff|woff2)$

{

    proxy_pass http://eisc.cn;

    proxy_set_header Host tx.kbash.cn;

    proxy_set_header X-Real-IP $remote_addr;

    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    proxy_set_header REMOTE-HOST $remote_addr;

    expires 12h;

}

location /

{

    proxy_pass http://eisc.cn;

    proxy_set_header Host tx.kbash.cn;

    proxy_set_header X-Real-IP $remote_addr;

    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    proxy_set_header REMOTE-HOST $remote_addr;

    

    add_header X-Cache $upstream_cache_status;

    

    #Set Nginx Cache

    

        add_header Cache-Control no-cache;

}


#PROXY-END/



#-------------------------------   官方案例    ---------------------------------------#

worker_processes auto;

error_log /var/log/nginx/error.log info;

events {

    worker_connections  1024;

}


stream {

    upstream backend {

        hash $remote_addr consistent;


        server backend1.example.com:12345 weight=5;

        server 127.0.0.1:12345            max_fails=3 fail_timeout=30s;

        server unix:/tmp/backend3;

    }


    server {

        listen 12345;

        proxy_connect_timeout 1s;

        proxy_timeout 3s;

        proxy_pass backend;

    }


    server {

        listen [::1]:12345;

        proxy_pass unix:/tmp/stream.socket;

    }

}




#-------------------------    已成功案例    ---------------------------------


user www-data;

worker_processes auto;

pid /run/nginx.pid;

include /etc/nginx/modules-enabled/*.conf;


events {

worker_connections 768;

# multi_accept on;

}



stream{

log_format proxy '$remote_addr [$time_local] '

'$status "$upstream_addr"';

upstream ipctcp_proxy {

hash $remote_addr consistent;

server eisc.cn:80 weight=5 max_fails=3 fail_timeout=30s;

server eisc.cn:37 weight=5 max_fails=3 fail_timeout=30s;

server eisc.cn:55 weight=5 max_fails=3 fail_timeout=30s;

}


server{

error_log /var/log/nginx/error.log;

access_log /var/log/nginx/access.log proxy;


listen 80;

listen 8080;

listen 37;

listen 55;

proxy_connect_timeout 1s;

proxy_timeout 3s;

proxy_pass ipctcp_proxy;

}

}

 0  已被阅读了672次  楼主 2021-09-11 21:43:37
回复列表
admin
2F
小绿叶技术Lv149   
https://blog.csdn.net/qq_22193519/article/details/90046496
 0   2021-12-02 08:27:49  回复

回复: nginx 301转跳,资源重定向:转发 反向解析代理,访问目的网站

guest
登录之后更精彩~
Powered by HadSky 7.7.16
© 2015-2022 PuYueTian
您的IP:8.219.134.200,2022-08-10 06:06:06,Processed in 0.0149 second(s).
Powered by HadSky
小绿叶技术博客