0

I am setting up a virtualhost that requires a password for a directory. I checked and the following entry works locally, but not on the server (Ubuntu). Do you have any tips what difference could be between the local and remote environment?

<VirtualHost example.com:443>
    ServerName example.com
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

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

    <Directory "/var/www/html/public">
        AuthType Basic
        AuthName "Restricted Content"
        AuthUserFile /etc/htpasswd/.htpasswd
        Require valid-user
    </Directory>
</VirtualHost>

The server has one more virtualhost in the /etc/apache2/sites-available/ folder, named 000-default.conf. This vhosts file is the same as mine, but without the Directory specification and with *:80 and without a ServerName.

I have 2 DNS-es for the server, I want one of them to request for a password.

5
  • What do you mean "works"? Asks for a password? And what is "local" and "on the server"? Local usually is on the server.
    – Halfgaar
    Sep 23, 2018 at 20:24
  • Local = Locally on my computer. And the issue is that on my computer it asks for a password, but on the server it doesn't
    – Tojas
    Sep 23, 2018 at 20:35
  • Do request from both origins end up in the access log you defined there? Are there other vhost definitions that have that access log? What are your other virtual host definitions? I'm guessing that when you access localhost on the server, you're using another virtual host.
    – Halfgaar
    Sep 23, 2018 at 20:51
  • I updated my post, based on your questions.
    – Tojas
    Sep 23, 2018 at 21:15
  • As far as I see, the logs are not working, because of the ${APACHE_LOG_DIR} is not specified. I will change it now to something absolute.
    – Tojas
    Sep 23, 2018 at 21:18

1 Answer 1

1

It's what I guessed in my comment: when you address the server from your PC, you're doing so by name, so you're hitting the code you pasted. When you're addressing the server locally (which is sysadmin talk for 'from/on the same machine'), you're hitting 000-default.conf.

You can probably remove the symlink /etc/apache2/sites-enabled/000-default.conf, because from what you said, it seems you want the above code to be the default virtual host, the website you will always get, no matter how you address the server.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .