1

I know this people have gone over this a thousand times, but I simply can't get my browser to resolve to 127.0.0.1 when I type in my domain name.

I'm developing a WP site locally. Getting to it by typing localhost works just fine, but when I type in the domain name, it won't resolve to localhost.

Can some one help me please?

/etc/hosts:

127.0.0.1 localhost thewriters.ink

/etc/apache2/apache2.conf:

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Require all denied
</Directory>

<Directory /usr/share> AllowOverride None Require all granted </Directory>

<Directory /var/www/html> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory>

/etc/apache2/sites-available/thewriterink.conf:

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
    ServerName thewriters.ink
    ServerAlias thewriters.ink
    ServerAdmin admin@ethewriters.ink

DocumentRoot /var/www/html
&lt;Directory /var/www/html&gt;
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Require all granted
&lt;/Directory&gt;

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log com

</VirtualHost>

vim: syntax=apache ts=4 sw=4 sts=4 sr noet

The reason I'm trying to do this is because I want the links within the website to be http://thewriters.ink and for plugins to use that URL so I don't have to go back and manually change dozens of links when its uploaded to the production server.

(I've disabled 000-default.conf and enabled thewritersink.conf using a2dissite and a2ensite.)

Thanks all for your help.
Robot876

1 Answers1

1

There are a couple of things that you can try to have the domain name resolve as you'd like.

Remember IPv6 in /etc/hosts

Try this:

127.0.0.1       localhost
127.0.0.1       thewriters.ink

The following lines are desirable for IPv6 capable hosts

::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters

::1 thewriters.ink

Note: While you can have multiple domains listed in a single row, I have found better support across distributions by putting each domain on its own row with the same IP addresses.

Remove duplicate lines and add a catch-all to your Apache virtual host config:

<VirtualHost *:80>
        ServerAdmin admin@ethewriters.ink
        DocumentRoot /var/www/html
    ServerName thewriters.ink
    ServerAlias *.thewriters.ink
    DirectoryIndex index.php index.html
    EnableMMAP Off

    &lt;Directory /var/www/html&gt;
            Options FollowSymLinks
            AllowOverride All
            Require all granted
    &lt;/Directory&gt;

    ErrorLog ${APACHE_LOG_DIR}/thewriters-error.log
    CustomLog ${APACHE_LOG_DIR}/thewriters-access.log combined

</VirtualHost>

Now you should be able to restart Apache and have everything "just work" ... so long as the Apache configuration file is enabled:

sudo service apache2 restart
matigo
  • 22,138
  • 7
  • 45
  • 75
  • Thanks. I'll try this in the afternoon. After posting I noticed I had duplication in the virtual host and deleted it, but it still wouldn't work. I'll try what you've suggested (and I didn't know I could use a wildcard...) Thanks. – robot876 Nov 05 '21 at 04:43