nginx 配置域名转发
自己测试环境,配置下载目录和一个jenkins的地址:
域名跳转,反向代理
# cat ../nginx.conf user www www; worker_processes 1; error_log logs/error.log info; pid logs/nginx.pid; worker_rlimit_nofile 65535; events { worker_connections 65535; use epoll; } http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '"$upstream_addr" $status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for" "$request_time" "$host"'; access_log logs/access.log main; sendfile on; keepalive_timeout 60; gzip on; client_max_body_size 50m; #缓冲区代理缓冲用户端请求的最大字节数,可以理解为保存到本地再传给用户 client_body_buffer_size 256k; client_header_timeout 3m; client_body_timeout 3m; send_timeout 3m; proxy_connect_timeout 300s; #nginx跟后端服务器连接超时时间(代理连接超时) proxy_read_timeout 300s; #连接成功后,后端服务器响应时间(代理接收超时) proxy_send_timeout 300s; proxy_buffer_size 64k; #设置代理服务器(nginx)保存用户头信息的缓冲区大小 proxy_buffers 4 32k; #proxy_buffers缓冲区,网页平均在32k以下的话,这样设置 proxy_busy_buffers_size 64k; #高负荷下缓冲大小(proxy_buffers*2) proxy_temp_file_write_size 64k; #设定缓存文件夹大小,大于这个值,将从upstream服务器传递请求,而不缓冲到磁盘 proxy_ignore_client_abort on; #不允许代理端主动关闭连接 upstream tomcat_test1 { server 192.168.37.108:8080; } upstream tomcat_2 { server 192.168.37.109:8080; } include /usr/local/nginx/conf/vhosts/*.conf; }
接下来是server 主机的配置:
# cat /usr/local/nginx/conf/vhosts/test.conf server { listen 80; server_name www.aliluo.top; location /images { root /; rewrite ^/image/(.*)$ /image/$1 break; access_log /usr/local/nginx/logs/test.log main; } location /upload { autoindex on; autoindex_exact_size on; autoindex_localtime on; alias /data/upload; access_log /usr/local/nginx/logs/upload.log main; } location /jenkins { #反向代理的地址 proxy_pass http://tomcat_2/jenkins; #设置主机头和客户端真实地址,以便服务器获取客户端真实IP proxy_set_header Host $host; proxy_set_header X-Real-Ip $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; access_log /usr/local/nginx/logs/tomcat_test1.log main; } }
启动nginx后,打来链接,就会出现jenkins界面,输入用户名,密码可以正常登陆:
登陆页面:
备注:
1)使用nginx的rewrite 同样可以是实现这个功能,可能配置上会有小许不同;
2)使用proxy_pass,如果跳转后输入用户名密码无法登陆,可能是由于以下参数没有配置,该参数具体含义可以参考nginx有关文章自行学习:
proxy_set_header Host $host;
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
本文来自博客园, 作者:Star-Hitian, 转载请注明原文链接:https://www.cnblogs.com/Star-Haitian/p/7771677.html