素材巴巴 > 程序开发 >

nginx rewrite url 跳转

程序开发 2023-09-12 19:11:46
upstream lbs {server localhost:8080;server localhost:8081;
 }server {listen       80;server_name  localhost;#access_log  /var/log/nginx/host.access.log  main;location / {root   /usr/share/nginx/html;#index  index.html index.htm;#index  test.html;}location /echo/ {root /usr/share/nginx/html;index test.html index.htm;if ( -f $request_filename ) {#echo "[$request_filename]";#echo "file exists.";}if ( $request_uri ~* ysj.html ) {rewrite ^ /echo/hn.html break;}}location /vote {root /usr/share/nginx/html;try_files $uri $uri /echo/hn.html;}location /hehe {root /usr/share/nginx/html;index hehe.html index.htm;}location /haha {alias /usr/share/nginx/html/haha;index haha.html index.htm;}location /file{root /usr/share/nginx/html;index file.html;default_type text/html;if ( -f $request_filename  ) {rewrite ^ /file_exists.html break;}if ( !-f $request_filename  ) {rewrite ^(.*)$ /file_not_found.html break;}}	location /api/ {proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://lbs;proxy_redirect default;}#error_page  404              /404.html;error_page 404	/404.html;# redirect server error pages to the static page /50x.html#error_page   500 502 503 504  /50x.html;location = /50x.html {root   /usr/share/nginx/html;}}
 

 

 

 

 

 

 

 


标签:

素材巴巴 Copyright © 2013-2021 http://www.sucaibaba.com/. Some Rights Reserved. 备案号:备案中。