LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-22-2022, 10:45 AM   #1
sirius_lee
LQ Newbie
 
Registered: Nov 2021
Posts: 10

Rep: Reputation: Disabled
Apache cannot resolve the hostname or is it dns?


I'm running a server with CentOS 8 and Apache 2.37 for hosting a wordpress site. That website should replace an old one, with the same domain name.
I edited inside and outside dns servers (bind) and added the ip address of a new server.

On the server itself, the /etc/hosts:
.
.
.
192.1.1.1 somesite.com


and I have changed only a few things in the default configuration files: /etc/httpd/conf/httpd.conf

Code:
#
ServerName somesite.com
#
...
#
DocumentRoot "/var/www/html"
#
# Further relax access to the default document root:
<Directory "/var/www/html">
#
 #
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride All

    #
    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>

and added digital certificates in /etc/httpd/conf.d/ssl.conf

Code:
<VirtualHost _default_:443>

# General setup for the virtual host, inherited from global configuration
#DocumentRoot "/var/www/html"
#ServerName www.example.com:443

# Use separate log files for the SSL virtual host; note that LogLevel
# is not inherited from httpd.conf.
ErrorLog logs/ssl_error_log
TransferLog logs/ssl_access_log
LogLevel warn

#   SSL Engine Switch:
#   Enable/Disable SSL for this virtual host.
SSLEngine on

#   List the protocol versions which clients are allowed to connect with.
#   The OpenSSL system profile is used by default.  See
#   update-crypto-policies(8) for more details.
#SSLProtocol all -SSLv3
#SSLProxyProtocol all -SSLv3

#   parallel.
#SSLCertificateFile /etc/pki/tls/certs/localhost.crt
SSLCertificateFile /etc/pki/tls/certs/somesite.com.crt
#   Server Private Key:
#   If the key is not combined with the certificate, use this
#   directive to point at the key file.  Keep in mind that if
#   you've both a RSA and a DSA private key you can configure
#   both in parallel (to also allow the use of DSA ciphers, etc.)
#   ECC keys, when in use, can also be configured in parallel
#SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
SSLCertificateKeyFile /etc/pki/tls/private/somesite.com.key
#   Server Certificate Chain:
#   Point SSLCertificateChainFile at a file containing the
#   concatenation of PEM encoded CA certificates which form the
#   certificate chain for the server certificate. Alternatively
#   the referenced file can be the same as SSLCertificateFile
#   when the CA certificates are directly appended to the server
#   certificate for convenience.
#SSLCertificateChainFile /etc/pki/tls/certs/server-chain.crt
SSLCertificateChainFile /etc/pki/tls/certs/DigiCertCA.crt
...
I don't have a virtual host, so I dont have a /etc/httpd/conf.d/somesite.conf file as I normally do.

The problem is:
When I type somesite.com in my webbrowser i get the site that I want but instead of domain name I see:

192.1.1.1

(and it shows no certificate, probably because it's ip address instead of somesite.com)

Apache configtest is ok and dns records are all ok.


What could be the issue? Could it be dns - more than 24h have passed and I do get the site, just not the address.
I have no idea what to try...
Can somebody help me?

Thanks!
Kind regards.

Last edited by sirius_lee; 02-23-2022 at 12:09 AM.
 
Old 02-22-2022, 11:17 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Hi,

Quote:
The problem is:
When I type somesite.com in my webbrowser i get the site that I want but instead of domain name I see:

172.16.1.202
You can run the following command to see what vhosts are defined in your apache configuration:
Code:
apachectl -S

Re. the SSL vhost:
Quote:
<VirtualHost _default_:443>

# General setup for the virtual host, inherited from global configuration
#DocumentRoot "/var/www/html"
#ServerName www.example.com:443
<snip>
You should use a DocumentRoot and a ServerName also in the SSL vhost and ditch the _default_ keyword in the vhost definition:
Code:
<VirtualHost *:443>

# General setup for the virtual host, inherited from global configuration
DocumentRoot "/var/www/html"
ServerName somesite.com
<snip>
 
Old 02-22-2022, 11:32 AM   #3
sirius_lee
LQ Newbie
 
Registered: Nov 2021
Posts: 10

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by bathory View Post
Hi,

You can run the following command to see what vhosts are defined in your apache configuration:
Code:
apachectl -S

Re. the SSL vhost:

You should use a DocumentRoot and a ServerName also in the SSL vhost and ditch the _default_ keyword in the vhost definition:
Code:
<VirtualHost *:443>

# General setup for the virtual host, inherited from global configuration
DocumentRoot "/var/www/html"
ServerName somesite.com
<snip>
In a moment of total desperation I've added a somesite.com.conf file with this configuration:
Code:
<VirtualHost *:443>
        SSLEngine on
        SSLCertificateFile /etc/pki/tls/certs/somesite.com.crt
        SSLCertificateKeyFile /etc/pki/tls/private/somesite.com.key
        SSLCertificateChainFile /etc/pki/tls/certs/DigiCertCA.crt
        DocumentRoot /var/www/html
        ServerName somesite.com
        ServerAlias www.somesite.com
</VirtualHost>
<VirtualHost *:80>
        ServerAdmin admin@somesite.com
        ServerName somesite.com
        ServerAlias www.somesite.com
        DocumentRoot /var/www/html
        Redirect "/" "https://somesite.com/"
        ErrorLog /etc/httpd/logs/error_log
        CustomLog /etc/httpd/logs/access_log combined
</VirtualHost>
Is that a bad idea?

This is what apachectl -S gives me back (thank you for the command btw):

Code:
VirtualHost configuration:
*:80                   somesite.com (/etc/httpd/conf.d/somesite.com.conf:10)
*:443                  is a NameVirtualHost
         default server somesite.com (/etc/httpd/conf.d/somesite.com.conf:1)
         port 443 namevhost somesite.com (/etc/httpd/conf.d/somesite.com.conf:1)
                 alias www.somesite.com
         port 443 namevhost 127.0.0.1 (/etc/httpd/conf.d/ssl.conf:40)
ServerRoot: "/etc/httpd"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/etc/httpd/logs/error_log"
Mutex authdigest-opaque: using_defaults
Mutex watchdog-callback: using_defaults
Mutex proxy-balancer-shm: using_defaults
Mutex rewrite-map: using_defaults
Mutex ssl-stapling-refresh: using_defaults
Mutex authdigest-client: using_defaults
Mutex lua-ivm-shm: using_defaults
Mutex ssl-stapling: using_defaults
Mutex proxy: using_defaults
Mutex authn-socache: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/etc/httpd/run/" mechanism=default
Mutex cache-socache: using_defaults
PidFile: "/etc/httpd/run/httpd.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="apache" id=48
Group: name="apache" id=48
This is the .htaccess file:

Code:
<IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
        RewriteBase /
        RewriteRule ^index\.php$ - [L]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . /index.php [L]

</IfModule>

# BEGIN WordPress


<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
#END WordPress
Do you maybe see any issue with this?
Thank you!

Last edited by sirius_lee; 02-22-2022 at 12:05 PM.
 
Old 02-22-2022, 12:33 PM   #4
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Quote:
This is what apachectl -S gives me back (thank you for the command btw):

VirtualHost configuration:
*:80 somesite.com (/etc/httpd/conf.d/somesite.com.conf:10)
*:443 is a NameVirtualHost
default server somesite.com (/etc/httpd/conf.d/somesite.com.conf:1)
port 443 namevhost somesite.com (/etc/httpd/conf.d/somesite.com.conf:1)
alias www.somesite.com
port 443 namevhost 127.0.0.1 (/etc/httpd/conf.d/ss
<snip>
So apachectl reports the correct vhosts
Did you restart apache after making the changes?
Also make sure that you clear your browser cache or use a different browser, before testing

Re. the .htaccess, it's ok.
It's the default .htacces for wordpress, but it's content is duplicated in your case!
 
Old 02-22-2022, 12:48 PM   #5
sirius_lee
LQ Newbie
 
Registered: Nov 2021
Posts: 10

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by bathory View Post
So apachectl reports the correct vhosts
Did you restart apache after making the changes?
Also make sure that you clear your browser cache or use a different browser, before testing

Re. the .htaccess, it's ok.
It's the default .htacces for wordpress, but it's content is duplicated in your case!
Of course, I've restarted it, maybe even a few times.
Sometimes, the site is still unreachable from different browsers and maybe from a phone etc, so I guess it's still dns propagation, but even when it works it's always ip address.

I've also seen this: https://serverpilot.io/docs/solution...ead-of-domain/ but the developer says that it fills automatically if everything is set correct. I've recently put up a server with similar configuration on centos 7, and it works as expected
and here I don't know where to check anymore.

If the dns zone and the main domain is somesite.com could it be a problem if the site has the same name?
 
Old 02-22-2022, 01:24 PM   #6
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
I don't use apache, I use nginx. But the principles are the same. My observations:
  • server_name is not required for this to work
  • your http => https redirection might be wonky. Can you try a web browser that does not automatically redirect? E.g. dillo.

Excerpt from my default config:
Code:
server {
    listen 80;
    listen [::]:80;
#### PERMANENT REDIRECT BEGIN ####
    #server_name example.com;
    return 301 https://$server_name$request_uri;
}
server {
#### PERMANENT REDIRECT END ####
    listen 443 ssl;
    listen       [::]:443 ssl;
    include ssl.conf;

    #server_name example.com;

    index index.html index.php;
<snip>
 
Old 02-22-2022, 02:55 PM   #7
sirius_lee
LQ Newbie
 
Registered: Nov 2021
Posts: 10

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by ondoho View Post
I don't use apache, I use nginx. But the principles are the same. My observations:
  • server_name is not required for this to work
  • your http => https redirection might be wonky. Can you try a web browser that does not automatically redirect? E.g. dillo.

Excerpt from my default config:
Code:
server {
    listen 80;
    listen [::]:80;
#### PERMANENT REDIRECT BEGIN ####
    #server_name example.com;
    return 301 https://$server_name$request_uri;
}
server {
#### PERMANENT REDIRECT END ####
    listen 443 ssl;
    listen       [::]:443 ssl;
    include ssl.conf;

    #server_name example.com;

    index index.html index.php;
<snip>
Even if I comment that line out, it still doesn't work. Now, I cannot even reach it from the outside network.
Ping works, nslookup shows the right address but I get nothing for www.somesite.com:

Code:
C:\Users\di>nslookup somesite.com
Server:  dns.google
Address:  8.8.8.8

Non-authoritative answer:
Name:    somesite.com
Address:  147.11.11.11

C:\Users\di>nslookup somesite.com
Server:  dns.google
Address:  8.8.8.8

*** dns.google can't find www.somesite.com: Non-existent domain
It seems my configuration isn't working at all.
 
Old 02-22-2022, 04:21 PM   #8
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Quote:
Even if I comment that line out, it still doesn't work. Now, I cannot even reach it from the outside network.
Ping works, nslookup shows the right address but I get nothing for www.somesite.com:

C:\Users\di>nslookup somesite.com
Server: dns.google
Address: 8.8.8.8

Non-authoritative answer:
Name: somesite.com
Address: 147.11.11.11

C:\Users\di>nslookup somesite.com
Server: dns.google
Address: 8.8.8.8

*** dns.google can't find www.somesite.com: Non-existent domain

It seems my configuration isn't working at all.
1. You should add in the dns an A RR pointing to the IP of your webserver
2. You should add the following in both http and https vhosts:
Code:
ServerAlias www.somesite.com
BTW the Redirect from the non SSL to the SSL enabled vhost is correct.
You can add also the "Permanent" keyword like this:
Code:
Redirect permanent / https://somesite.com/

Last edited by bathory; 02-22-2022 at 04:30 PM.
 
Old 02-22-2022, 09:21 PM   #9
sirius_lee
LQ Newbie
 
Registered: Nov 2021
Posts: 10

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by bathory View Post
1. You should add in the dns an A RR pointing to the IP of your webserver
2. You should add the following in both http and https vhosts:
Code:
ServerAlias www.somesite.com


BTW the Redirect from the non SSL to the SSL enabled vhost is correct.
You can add also the "Permanent" keyword like this:
Code:
Redirect permanent / https://somesite.com/
1. In my internal dns it goes:
somesite.com 192.1.1.1 - > internal ip

in both master and slave.
In my external dns
somesite.com 1.1.1.1 - > outside ip, in both master and slave.

Is it possible that the name of the domain cannot be the same as the website?
There are many entries in the dns that go like this:

Site1.somesite.com ip
site2.somesite.com ip
...
site50.somesite.com ip

But the main site should be somesite.com ip
Is there a naming problem? I don't think that should be an issue...
2. There are aliases in both, yes, but the site cannot be open outside of my network, just internally and it always shows ip address.

I'm seriously considering that this might be the wordpress problem, because it was apparently installed with ip address.

The ping works for both external ip and the site name, also nslookup shows correct outside address and tracert shows unreachable after couple of hops but then resumes to the correct address.
 
Old 02-23-2022, 02:17 AM   #10
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Quote:
1. In my internal dns it goes:
somesite.com 192.1.1.1 - > internal ip

in both master and slave.
In my external dns
somesite.com 1.1.1.1 - > outside ip, in both master and slave.

Is it possible that the name of the domain cannot be the same as the website?
There are many entries in the dns that go like this:

Site1.somesite.com ip
site2.somesite.com ip
...
site50.somesite.com ip

But the main site should be somesite.com ip
Is there a naming problem? I don't think that should be an issue...
From the dns perspective just make sure that www.somesite.com resolves to the same IP as the plain somesite.com

Quote:
2. There are aliases in both, yes, but the site cannot be open outside of my network, just internally and it always shows ip address.

I'm seriously considering that this might be the wordpress problem, because it was apparently installed with ip address.
The ServerAlias is not going to work if there is no entry for www.somesite.com in the dns.

Showing the IP address instead of the hostname, it could be the wordpress problem you mentioned in your #5 post above.
Did you follow the instructions there to see if it solves that issue?
 
Old 02-23-2022, 03:00 AM   #11
sirius_lee
LQ Newbie
 
Registered: Nov 2021
Posts: 10

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by bathory View Post
From the dns perspective just make sure that www.somesite.com resolves to the same IP as the plain somesite.com

The ServerAlias is not going to work if there is no entry for www.somesite.com in the dns.

Showing the IP address instead of the hostname, it could be the wordpress problem you mentioned in your #5 post above.
Did you follow the instructions there to see if it solves that issue?
I put www.somesite.com as an alias of somesite.com, I hope that's going to work.
It doesn't yet, but maybe it will.

As for wordpress, I've just contacted the developer, let's see if he is willing to do something.

Thank you for staying with me, this is a nightmare.
 
  


Reply

Tags
apache 2.4.7, dns



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
dns client cannot resolve on dns server jtvillegas Linux - Software 3 03-12-2016 03:30 PM
HOSTNAME = hostname -> HOSTNAME: command not found ? thomas2004ch Linux - Software 2 08-26-2013 08:25 PM
How I can resolve the error Postfix? warning: hostname does not resolve to address kanzer Linux - Server 1 03-22-2013 08:56 AM
clients CAN resolve hostname of server w/nslookup, but CANNOT access by hostname WTF? psycroptic Linux - Networking 9 11-10-2012 11:24 AM
DNS can't resolve gmail.com but can resolve everything else? TongueTied Linux - Networking 2 01-24-2006 03:39 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration