apache rewrite to nginx

Aleksandar Lazic al-nginx at none.at
Wed Jun 14 20:26:14 UTC 2017


Hi frank3427.

frank3427 wrote on 14.06.2017:

> so far I have come up with the following but , I have been reading that
> using if statements is bad.
>
> if ($http_host ~ "^rwa-(.*)"){
> set $rule_0 1;
> set $bref_2 $2;
> set $bref_7 $7;
> }
> if ($http_host ~ "^m2m-(.*)"){
> set $rule_0 1;
> set $bref_2 $2;
> set $bref_7 $7;
> }
> if ($http_host ~ "^dwa-(.*)"){
> set $rule_0 1;
> set $bref_2 $2;
> set $bref_7 $7;
> }
> if ($rule_0 = "1"){
> rewrite ^/(/ws/v[1-9]/dias/[^+]*)\+([^+]*)$
> https://${host_finder:$http_host}/$1\$bref_2B$2https://$$bref_7bhost_finder:$bref_25$bref_7bHTTP_HOST$bref_7d$bref_7d/$1/$bref_2B$2
> last;
> }
> if ($http_host ~ "^rwa-(.*)"){
> set $rule_1 1;
> set $bref_2 $2;
> }
> if ($http_host ~ "^m2m-(.*)"){
> set $rule_1 1;
> set $bref_2 $2;
> }
> if ($http_host ~ "^dwa-(.*)"){
> set $rule_1 1;
> set $bref_2 $2;
> }
> if ($rule_1 = "1"){
> rewrite ^/(/ws/v[1-9]/dias/.*)\+(.*)$ /$1\$bref_2B$2;
> }
> if ($http_host ~ "^rwa-(.*)"){
> set $rule_2 1;

Missing '}'

The config does not run in nginx and makes no sense?

I have installed nginx on a plain linux added the conf to 
/etc/nginx/conf.d/default.conf and run nginx -t

###
nginx -t
nginx: [emerg] the closing bracket in "host_finder" variable is missing in /etc/nginx/conf.d/default.conf:31
nginx: configuration file /etc/nginx/nginx.conf test failed
###

Please read again

http://nginx.org/en/docs/http/server_names.html
http://nginx.org/en/docs/njs_about.html
http://nginx.org/en/docs/http/ngx_http_js_module.html
https://www.nginx.com/blog/tag/nginscript/

Untested suggestion without the host_finder call.

##
server {
  server_name ~^(?<prefix>rwa|m2m|dwa)-(?<postfix>.*)$;

  location / {
    rewrite ^(/ws/v[1-9]/dias/[^+]*)\+([^+]*)$ https://$prefix/$1\%2B$2 redirect;
  }
}
##

-- 
Best Regards
Aleks



More information about the nginx mailing list