I am using NGINX to try and make a Django / uWSGI website publicly unreachable via bare IP address while setting up a domain with these rules:
my-domain.com/my-new-base
should be reachable via my-domain.com
,
my-domain.com/my-new-base
should not be reachable directly (or at least should redirect to my-domain.com
).
I wrote the config as follows, but I do not seem to be able to write the locations in a way that works:
server {
listen 80 default_server;
server_name "";
return 444;
}
server {
listen 80;
server_name my-domain.com;
location = / {
rewrite ^/(.*)$ /my-new-base$1 break;
include /etc/nginx/uwsgi_params;
uwsgi_pass app:8000;
}
location /my-new-base {
return 301 $scheme://my-domain.com;
}
}
Here are the uWSGI params I am including above:
uwsgi_param QUERY_STRING $query_string;
uwsgi_param REQUEST_METHOD $request_method;
uwsgi_param CONTENT_TYPE $content_type;
uwsgi_param CONTENT_LENGTH $content_length;
uwsgi_param REQUEST_URI $request_uri;
uwsgi_param PATH_INFO $document_uri;
uwsgi_param DOCUMENT_ROOT $document_root;
uwsgi_param SERVER_PROTOCOL $server_protocol;
uwsgi_param REMOTE_ADDR $remote_addr;
uwsgi_param REMOTE_PORT $remote_port;
uwsgi_param SERVER_ADDR $server_addr;
uwsgi_param SERVER_PORT $server_port;
uwsgi_param SERVER_NAME $server_name;
But all this results in an infinite loop.
question from:
https://stackoverflow.com/questions/65951129/nginx-disallow-public-ip-access-rewrite-base-url 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…