Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use valid_referers if server_name is set by a env. variable #581

Closed
venomone opened this issue Feb 5, 2020 · 5 comments
Closed

Comments

@venomone
Copy link

venomone commented Feb 5, 2020

Hello,

im currently facing an issue, imagin the following nginx.conf:

env NGINX_SERVERNAMES;
...
server {
        set_by_lua $curr_server_name 'return os.getenv("NGINX_SERVERNAMES")';
        server_name $curr_server_name;
        valid_referers none blocked server_names;

i would expect that "server_names" is using server_name which i again load by a env. variable "env NGINX_SERVERNAMES;"
but for some reason NGINX openresty/nginx returns the following error at the log:

2020/02/05 12:23:59 [emerg] 151#151: conflicting parameter "$curr_server_name" in /etc/nginx/nginx.conf:185

So how can i use valid_referers together with my server_name variable on openresty?

I also tryd the following:

valid_referers none blocked server_names $curr_server_name;
valid_referers none blocked $curr_server_name;

Which is also not working as expected.

@agentzh
Copy link
Member

agentzh commented Feb 6, 2020

@venomone It seems that you're having a directive running order issue. Do you know that set_by_lua always runs after server_name even if you put the former before the latter in the nginx.conf file?

@venomone
Copy link
Author

venomone commented Feb 6, 2020

@agentzh no i was not aware f it. im using openresty now since a week or so and im still thinking the NGINX way here i guess. So is there any solution for this problem?

@agentzh
Copy link
Member

agentzh commented Feb 9, 2020

@venomone Easy. For your purposes, you can just do the “Referer” request header check all in Lua, like, say, in rewrite_by_lua_block.

@agentzh agentzh closed this as completed Feb 9, 2020
@venomone
Copy link
Author

Do you maybe have a full example here, maybe a copy-paste example from you config or so. currently you have to derive everything yourself. Would be awesome, thank you.

@agentzh
Copy link
Member

agentzh commented Feb 10, 2020

@venomone You can use the ngx.var API to fetch the Referer request header and then check it against the dynamic value you set. It should be trivial enough. Consult the ngx_lua manual for more details about these API functions and directives. I don't have the time to prepare example code for every open source user. Sorry. You may also ask in the openresty-en mailing list for further assistant for example. This place is for bug report only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants