我正在尝试使用我的 nginx 配置来拒绝与特定模式匹配的请求,但仅限于特定的服务器名称。我不确定如何做到这一点,尽管假如邪恶我尝试与我不想接收请求的服务器进行比较$server_name
并返回 403。这种方法根本不起作用。
我想要阻止的请求经过 URL 重写。nginx 服务器配置根据server_name
指令处理多个域。
location / {
try_files $uri @rewrite;
}
location @rewrite {
rewrite ^ /index.php;
}
我想阻止对user
和的请求,user/register
但前提是使用的服务器名称是example.com
我有点被困在这里因为我从来没有做过这样的事。
这是当前的 nginx 配置:
server {
listen 192.168.0.10:80;
server_name server.intranet company.com;
access_log /home/company/access_log;
error_log /home/company/error_log;
root /home/company/intranet;
location = /favicon.ico {
access_log off;
}
location = /robots.txt {
allow all;
access_log off;
}
location ~* \.(txt|log) {
allow 127.0.0.1;
deny all;
}
location ~ \..*/.*\.php$ {
allow 192.168.0.0/16;
deny all;
}
location ~ ^/sites/.*/private/ {
return 403;
}
location ~ (^|/)\. {
return 403;
}
location / {
try_files $uri @rewrite;
}
location @rewrite {
rewrite ^ /index.php;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php-fpm/company-socket;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_intercept_errors on;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name;
}
location ^/sites/.*/files/styles/ {
try_files $uri @rewrite;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
}
}