You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CentOS7+Virtualmin+Nginx环境下如何设置网站仅内网访问/离线模式?

Hey Eric, since you're using Virtualmin with Nginx on CentOS 7, here are a few reliable, straightforward ways to restrict your site to internal-only access or put it into offline mode to block external crawlers like Google:

方法1:通过Nginx配置直接限制内网访问

This is the most direct approach, as it leverages Nginx's core access control capabilities:

  • Log into Virtualmin, navigate to your target website, then go to Services > Configure Website > Edit Directives (this lets you edit raw Nginx config for the site).
  • Inside the server block, add these rules (replace the IP ranges with your actual internal network segments, e.g., 10.0.0.0/8 for a typical private network):
    # Allow internal IPs and local loopback
    allow 192.168.0.0/24;
    allow 127.0.0.1;
    # Block all other external traffic
    deny all;
    
  • Save the changes, then restart Nginx to apply them:
    sudo systemctl restart nginx
    
  • Test it out: External devices should get a 403 Forbidden error, while internal devices can access the site normally.
方法2:设置离线(维护)模式 + 内网限制

If you want to show a friendly maintenance page to external visitors while keeping access open internally:

  1. First, create a simple maintenance page (save it to your site's public directory, e.g., /home/yourdomain/public_html/maintenance.html):
    <!DOCTYPE html>
    <html>
    <head>
        <title>Site Under Maintenance</title>
        <style>body { text-align: center; margin-top: 50px; font-family: Arial; }</style>
    </head>
    <body>
        <h1>We're Performing Maintenance</h1>
        <p>Our site will be back online soon. Thank you for your patience!</p>
    </body>
    </html>
    
  2. Go back to the Nginx directive editor in Virtualmin, and add these rules to the server block:
    # Allow internal IPs only
    allow 192.168.0.0/24;
    allow 127.0.0.1;
    deny all;
    
    # Serve maintenance page for blocked requests
    error_page 403 /maintenance.html;
    location = /maintenance.html {
        root /home/yourdomain/public_html;
        internal; # Prevent direct access to this page from external sources
    }
    
    # Block crawlers even if they slip through (extra layer)
    add_header X-Robots-Tag "noindex, nofollow" always;
    
  3. Restart Nginx with sudo systemctl restart nginx — external visitors will see your maintenance page, and internal users get full access.
方法3:Use Virtualmin's Graphical Access Control (No Manual Config)

If you prefer a point-and-click interface instead of editing config files:

  • In your website's Virtualmin dashboard, go to Security > Access Control.
  • In the Allowed IP addresses field, add your internal network range(s) (e.g., 192.168.0.0/24) plus 127.0.0.1.
  • In the Denied IP addresses field, type all to block everything else.
  • Click Save — Virtualmin will automatically update the Nginx config and restart the service for you.

内容的提问来源于stack exchange,提问作者Eric

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 06:17:51