System Status
Buy Now
  • Email & Apps
  • Office 365
Login
  • MyRackspace Portal
  • Cloud Control Panel
  • Rackspace Webmail Login
  • Cloud Office Control Panel
  • Support Home
  • How-To
  • Developer Documentation
  •  Blogs 
    • Expert Insights Tech Blog
    • Rackspace Blog
    • Solve: Thought Leadership

Support Network

End-to-End Multicloud Solutions.   Solving Together.™   Learn more at Rackspace.com

How–To Home

Cloud Servers

  • Introduction
  • FAQ
  • All Articles

Check Linux configuration files for syntax errors

Last updated on:  2020-05-08

Authored by:  Matthew Brown


This article describes how to check the Linux® configuration for Secure Shell (SSH), Apache®, and Nginx®, which helps you to troubleshoot errors. For example, you might make a change to a configuration file and introduce a syntax error. As a result, when you restart or reload the service, it shows an error and fails to restart, which results in downtime.

SSH

You can find the SSH configuration file in /etc/ssh/sshd_config. After you change the configuration file, run the command sshd -t to check the configuration. If the configuration has errors, the following error message displays:

# sshd -t

/etc/ssh/sshd_config: line 17: Bad configuration option: ZPort
/etc/ssh/sshd_config: terminating, 1 bad configuration options

If there are no errors, nothing displays when you run the command.

Apache

The syntax check command checks the default Apache configuration file and any virtual hosts (vhosts) that you have configured on the server. To check the syntax, run httpd -t or apache2ctl -t for the Ubuntu® operating system and Debian®. If there is an error with the syntax check, the error message displays output similar to the following example:

# httpd -t

AH00112: Warning: DocumentRoot [/var/www/test.com/httpdocs] does not exist
AH00526: Syntax error on line 3 of /etc/httpd/conf.d/test.conf:
ServerName takes one argument, The hostname and port of the server

If there are no errors, the message Syntax OK displays. Even if there are no vhosts on the server, the syntax check still shows Syntax OK when the syntax for the default configuration file for Apache is correct.

Nginx

Nginx syntax checks behave differently than Apache. To check the syntax of the default Nginx configuration, run the command nginx -t. However, if you want to check the syntax of a specific server block, you need to add the -c flag and specify the path to the server block as shown in the following example:

[root@localhost ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

[root@localhost ~]# nginx -t -c /etc/nginx/conf.d/test.com.conf
nginx: [emerg] "server" directive is not allowed here in /etc/nginx/conf.d/test.com.conf:1
nginx: configuration file /etc/nginx/conf.d/test.com.conf test failed

Share this information:

©2020 Rackspace US, Inc.

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License

See license specifics and DISCLAIMER

About Rackspace
  • About
  • Customer Stories
  • Events
  • Programs
Blogs
  • The Rackspace Blog
  • Expert Insights Tech Blog
  • Solve: Thought Leadership
  • News
  • Contact Information
  • Legal
  • Careers
Site Information
  • Style Guide for Technical Content
  • Trademarks
  • Privacy Statement
  • Website Terms
Support Network
  • Support Network Home
  • Rackspace How-To
  • API Documentation
  • Developer Center
  • ©2020 Rackspace US, Inc.