【发布时间】:2020-10-20 13:17:03
【问题描述】:
我有一个我想通过负载均衡器后面的 nginx 在我的服务器上允许的 IP 地址列表。我目前正在从 apache 迁移到 nginx,我之前在 apache 中的设置是这样的:
RewriteBase /
RewriteCond %{REMOTE_HOST} !^123.456.123.789
RewriteCond %{REMOTE_HOST} !^456.123.789.123
RewriteCond %{REMOTE_HOST} !^123.567.456.789
RewriteCond %{REMOTE_HOST} !^123.456.789.100
RewriteCond %{REMOTE_HOST} !^127.0.0.1
RewriteCond %{REQUEST_URI} !/maintenance.php$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif|css|js|api) [NC]
RewriteRule .* /maintenance.php [R=302,L]
我想通过重定向除 ip 地址列表之外的所有请求在 nginx 中应用类似的方法。
location / {
if ($remote_host !~ "^123.456.123.789"){
rewrite ^(.*)$ /maintenance.php redirect;
}
if ($remote_host !~ "^456.123.789.123"){
rewrite ^(.*)$ /maintenance.php redirect;
}
if ($remote_host !~ "^123.567.456.789"){
rewrite ^(.*)$ /maintenance.php redirect;
}
if ($remote_host !~ "^123.456.789.100"){
rewrite ^(.*)$ /maintenance.php redirect;
}
if ($remote_host !~ "^127.0.0.1"){
rewrite ^(.*)$ /maintenance.php redirect;
}
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
}
【问题讨论】:
标签: laravel nginx amazon-elastic-beanstalk