圆月山庄资源网 Design By www.vgjia.com
最近项目中涉及到旧老项目迁移,需要在nginx上做些配置,所以简单学习了下,好记性不如烂笔头,先记下来。
rewrite
首先查看下nginx是否支持rewrite:
./nginx -V
不支持说明安装nginx时候缺少pcre,需要重新安装nginx:
#安装pcre wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.34.tar.gz tar -zxvf pcre-8.34.tar.gz cd pcre-8.34 ./configure make make install #安装nginx cd nginx-1.0.12 ./configure --conf-path=/usr/local/nginx/conf/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.34 make make install #启动nginx ./nginx #重启nginx ./nginx –s reload
示例:
比如现有如下的nginx配置:
worker_processes 24; #worker_cpu_affinity 0000000000000001; worker_rlimit_nofile 65535; error_log logs/error.log crit; pid logs/nginx.pid; events { use epoll; worker_connections 2048000; } http { include mime.types; default_type application/octet-stream; charset utf-8; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 60; client_max_body_size 10m; client_body_buffer_size 128k; upstream log { server 192.168.80.147:8338; } server { listen 6061; server_name 192.168.71.51; location / { proxy_pass http://log; proxy_redirect off; proxy_set_header Host $host; proxy_set_header Remote_Addr $remote_addr; proxy_set_header X-REAL-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_connect_timeout 90; proxy_send_timeout 90; proxy_read_timeout 90; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } log_format log '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log logs/access_log.log log; #设定查看Nginx状态的地址 location /NginxStatus { #stub_status on; access_log on; auth_basic "NginxStatus"; #auth_basic_user_file conf/htpasswd; } } }
现在需要作如下的重定向:
192.168.71.51/log.aspx –> 192.168.80.147:8338/log
192.168.71.51/do.aspx –> 192.168.80.147:8338/do
192.168.71.51/uplog.aspx –> 192.168.80.147:8338/log
可以如下配置:
server { listen 6061; server_name 192.168.71.51; rewrite ^(.*)("http://192.168.71.51:6061/do1.aspx">http://192.168.71.51:6061/do1.aspx"htmlcode">…… upstream other { server 192.168.71.41:2210; } ……然后在location里增加如下的判断即可:
…… location / { if ( $query_string ~* ^(.*)c=config\b|uplog\b(.*)$ ){ proxy_pass http://other; } ……关键是标红的行,$query_string表示url参数,后面是标准的正则匹配,需要的注意的是nginx中if有很多限制,语法很苛刻,具体参看上面的文档。
很简单却很实用的配置,希望能帮到正在找这方面信息的同学。
圆月山庄资源网 Design By www.vgjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
圆月山庄资源网 Design By www.vgjia.com
暂无评论...
更新日志
2024年09月20日
2024年09月20日
- 魏新雨《为你祈祷+新歌精逊2CD[WAV]
- 影心、明萨拉你选哪个?国外美女COS《博德3》
- 澳洲女子骑车跌入“自杀树”丛 疼痛持续9个月崩溃
- 育碧公布2024“她创力”计划:为女性游戏人提供辅导
- 刘美君.2017-千色·30总选3CD【环球】【WAV+CUE】
- 群星.2022-星河长明电视原声带【乐有奇思】【FLAC分轨】
- 陈淑桦.1995-淑桦盛开Forever【滚石】【WAV+CUE】
- 《再来一张》评测:出师成败皆系“赌”
- 《银河汉堡店》测评:我是银河走菜王!
- 《末日地带2》评测:酣畅淋漓的“和面”之旅
- 萧煌奇《没事的》[320K/MP3][96.22MB]
- 萧煌奇《没事的》[FLAC/分轨][263.38MB]
- 群星《音你而来 第6期》[320K/MP3][90.61MB]
- 交错战线爬塔攻略一览
- 战锤40K星际战士2全近战武器使用教学|近战武器连招表