#---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;
}
# 说明:讲不带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 ;
listen 443;
server_name kbash.cn www.kbash.cn;
location / {
proxy_pass http://82.157.148.144:80;
index index.php index.html;
}
}
#------------- 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;
}
}
#---------------------------------------------------------------------#
1 nginx修改root映射
修改root映射实现nginx目录访问重定向是最简单的方式, 推荐采用这一种.
location /image {
root /folderName;
}
2 通过nginx rewrite内部跳转实现访问重定向
nginx配置代码示例:
location /image {
rewrite ^/image/(.*)$ /folderName/image/$1 last;
}
3 nginx设置别名alias映射实现
配置示例:
location /image {
alias /folderName/image; #这里写绝对路径
}
4 通过nginx的permanent 301绝对跳转实现
配置示例:
location /image {
rewrite ^/image/(.*)$ http://dashidan.com/folderName/image/$1;
}
5 通过判断uri实现页面跳转
配置示例:
if ( $request_uri ~* ^(/image)){
rewrite ^/image/(.*)$ /folderName/image/$1 last;
}
原文链接:https://blog.csdn.net/sinbadfreedom/article/details/79494702
tcp 转发:https://www.cnblogs.com/baolin2200/p/7803511.html
请注意,stream配置不能放到http内,即不能放到/etc/nginx/conf.d/,因为stream是通过tcp层转发,而不是http转发
stream {
# 添加socket转发的代理
upstream socket_proxy {
hash $remote_addr consistent;
# 转发的目的地址和端口
server 192.168.1.100:9000 weight=5 max_fails=3 fail_timeout=30s;
}
# 提供转发的服务,即访问localhost:9001,会跳转至代理socket_proxy指定的转发地址
server {
listen 9001;
proxy_connect_timeout 1s;
proxy_timeout 3s;
proxy_pass socket_proxy;
}
}