Skip to main content

Info for deny some locations ( nginx )

Comments

4 comments

  • manoj bajpai

    You're right—Nginx does not allow location directives inside conf.d/*.conf files unless they are inside a server block. Since you are using Nginx as a proxy, you need to modify the appropriate server block.

    Solution

    Instead of placing your location directive directly in /etc/nginx/conf.d/block.conf, you should modify your existing Nginx server block configuration.

    Steps to Fix

    1. Edit the main Nginx configuration file or an existing site-specific config in /etc/nginx/conf.d/

      • Open the default or virtual host configuration file where the server block is defined.
      • Typically, this is found in /etc/nginx/conf.d/default.conf or /etc/nginx/nginx.conf.
    2. Modify the configuration file

      • Add the location block inside the server block.
      server {
          listen 80;
          server_name yourdomain.com;
      
          location = /xmlrpc.php {
              deny all;
          }
      
          # Other existing configurations
      }
      
    3. Save and test the configuration Run:

      nginx -t
      

      If there are no errors, restart Nginx:

      systemctl restart nginx
      

    Alternative (Using include Directive)

    If you want to keep the rule in a separate file (like block.conf), you need to modify your main Nginx configuration to include it inside a server block.

    1. Edit your main server block (e.g., /etc/nginx/conf.d/default.conf)

      server {
          listen 80;
          server_name yourdomain.com;
      
          include /etc/nginx/conf.d/block.conf;
      }
      
    2. Modify /etc/nginx/conf.d/block.conf to contain only the location directive:

      location = /xmlrpc.php {
          deny all;
      }
      
    3. Test and reload Nginx

      nginx -t && systemctl reload nginx
      

    Let me know if you need further clarification! 

    0
  • Pietro Leone

    Hello,

    thanks for your help.

    I am following your instruction . i have a default.conf in the folder.

    after editing this file it seems that the configuration has not changed. i am looking into verbose nginx -T command and i not found new location i add before...

    may be i need rebuild something ? thanks

    0
  • Pietro Leone

    i am stucked here...

    any help before i open ticket ? thanks

    0
  • cPRex Jurassic Moderator

    It would likely be best to open a ticket on this one so the system can be examined directly.

    0

Please sign in to leave a comment.