1

This was working (or it appeared to be) earlier today, but I restarted my server recently, and now Apache seems to not be acknowledging my port 80 vhost.

My site is served from /var/www/example.com/public_html, and port 80 should be redirecting to HTTPS. Before my server restart, this was working; now it's not redirecting and is serving the default content from /var/www/html.

I'm not sure if there's some process or service I may have needed to start after the server restart? The site is enabled and the port 443 vhost is working as expected. Apache version is 2.4.27 and OS is Ubuntu 17.10. This my conf file in /etc/apache2/sites-available/example.com.conf.

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule ssl_module modules/mod_ssl.so

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com/public_html

    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteCond %{HTTPS} !=on
        RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
    </IfModule>
</VirtualHost>

<VirtualHost *:443>
    SSLEngine On
    SSLCertificateKeyFile /etc/ssl/private/example_com.key
    SSLCertificateFile /etc/ssl/certs/example_com.crt
    SSLCertificateChainFile /etc/ssl/certs/example_com.ca-bundle

    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com/public_html
    ProxyPreserveHost On
    ProxyPass /api http://localhost:1337/api
    ProxyPassReverse /api http://localhost:1337/api

    <directory /var/www/example.com/public_html/>
        Options -Indexes +FollowSymLinks +MultiViews
        AllowOverride All
        Require all granted

        <IfModule mod_rewrite.c> 
            RewriteEngine On
            RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
            RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule (.*) index.html [L]
        </IfModule> 
    </directory>
</VirtualHost>
2

Do you have the following in your config(s) somewhere?

NameVirtualHost *:80
NameVirtualHost *:443

Those need to match what you use in the <VirtualHost> blocks

  • 1
    Thanks, this helped lead me to figuring out the core issue. The default site with an unnamed 80 host was enabled, which I guess suddenly began overriding my site config. Ensuring everything was named and disabling the unused site is now allowing it work as expected. :) – Chrysus Oct 29 '17 at 3:18
  • since 2.4 the NameVirtualHost directive is ignored... httpd.apache.org/docs/current/mod/core.html#namevirtualhost – Tom H Mar 9 '18 at 16:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.