mirror of
https://github.com/FiloSottile/mkcert.git
synced 2026-04-25 13:36:02 +03:00
[GH-ISSUE #56] Apache configuration on macOS #31
Labels
No labels
TLS stack issue
Windows
bug
duplicate
duplicate
enhancement
help wanted
help wanted
pull-request
question
question
root store
waiting for info
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/mkcert#31
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @fooness on GitHub (Aug 14, 2018).
Original GitHub issue: https://github.com/FiloSottile/mkcert/issues/56
After following all steps in the README for macOS and generating certificates for
localhost+7in~/Sites/_certificates/, I wonder if there’s some special configuration settings for macOS’ built in Apache (with vhosts).Would be happy if anyone using
mkcerton macOS could share their experiences on how to getmkcertup and running.@nickkaczmarek commented on GitHub (Aug 15, 2018):
I'm using it on macos, but only for local development with webpack dev server, but with that you effectively just run
mkcert -installwhich I believe creates a local trusted Certificate Authority and then in the project, and maybe this part isn't strictly necessary to run in the project, but I runmkcert hostnameand then point webpack dev server to that. In this case I ranmkcert localhostbecause webpack starts the server atlocalhost:3001. I could be wrong about my explanations, but this process is working for me so far. I'm sure @FiloSottile would have more insight into the inner workings.@loilo commented on GitHub (Aug 29, 2018):
I got my Apache VHosts to work successfully with
mkcert.The example below corresponds to my setup of mapping
[anything].dev.localhostto/Users/[username]/Sites/[anything], where[username]is the user I'm running on my machine.It works with the help of dnsmasq.
My pre-existing VHost configuration:
I created a
.crtfolder in/Users/[username]/Sitesand executed the following command in there:Subsequently, I added the following configuration block to my Apache config. As you can see, if you compare it to the HTTP block above, it's pretty straightforward:
Hope this helps.
@fooness commented on GitHub (Aug 30, 2018):
Thank you very much, @Loilo … that’s exactly what I’m looking for. I added your lines (excluding the combined custom and error log) to my
/etc/apache2/extra/httpd-vhosts.conf… I suppose I still need to specify a<Directory "…">block like the following, is this correct?I think it might be working now, though unfortunately I still get invalid/insecure certificate errors in Chromium and Firefox. Any ideas on what’s the problem? Or do both browser not support wildcard certificates?
How was dnsmasq configured? For an older setup with another approach, I’m having a file called
/etc/resolver/devwith an entry ofnameserver 127.0.0.1…dev/*.dev, in my case, corresponds to yourServerAliasof*.localhost…Does anything need to be defined in
/etc/apache2/extra/httpd-ssl.conf? Do you useSSLEngine onand server wideSSLCertificateFile/SSLCertificateKeyFilesomewhere?What exactly does
%-2+stand for?@loilo commented on GitHub (Aug 30, 2018):
So, in order:
Yes, you still need the
<Directory>directive.Mine looks like this:
My setup works just fine in Chrome and Firefox, so it's probably not the browsers.
dnsmasq
I'm assuming you installed dnsmasq via Homebrew.
$(brew --prefix)/etc/dnsmasq.conf, add the line/etc/resolver/localhost, and add to it the following line:brew services restart dnsmasq)SSL
I'm not really sure what exactly is required to be configured. I'm by no means an Apache expert and it's been a while ago that I set up my local webserver.
I'm having the
ssl_moduleenabled in myhttpd.conf:Regarding your question, I definitely have an
httpd-ssl.confincluded in the mainhttpd.confwhich contains aListen 443. There's some other stuff I don't think is relevant to your case. It's also the default content that pre-existed in that file, I haven't touched it at all.%-2+This is a token which Apache replaces with the 2nd level domain. If you're on
foo.localhost, that's going to befoo. If you had a setup with deeper nested domains, likefoo.bar.localhost,%-2+will bebarwhile%-3+will befoo.I assume you have already restarted your Apache after adjusting your config?
@fooness commented on GitHub (Aug 30, 2018):
In regards of
dnsmasq.conf, the only difference is I’m having a.in front of my top level domain, likeaddress=/.dev/127.0.0.1in my case, which in your case would correspond toaddress=/.localhost/127.0.0.1…Everything else in my setup pretty much matches yours.
Virtualhosts syntax/config check:
And I restarted Apache several times via
sudo apachectl -k restart, yes. Unfortunately without success. Really can’t figure out the problem here, unfortunately. Thank you very much for your efforts!@loilo commented on GitHub (Aug 30, 2018):
You're welcome. Sorry it didn't work out. 😕
@fooness commented on GitHub (Aug 30, 2018):
Maybe someone else sees a problem we just didn’t recognize.
@loilo commented on GitHub (Aug 30, 2018):
For the record, I'm not using macOS' built-in Apache but a version installed from Homebrew. I don't think that it matters, but for finding problems every tiny bit could be relevant.
@fooness commented on GitHub (Aug 30, 2018):
Maybe it’s just the
mkcertcertificates that are wrong …I was just testing everything in Safari, which I normally don’t use, and there I got a message like:
“input”, being it the URL, is
[foldername].dev(or.localhostin your case).@loilo commented on GitHub (Aug 30, 2018):
Also
.devis a registered TLD, I don't know how that interferes with stuff.@fooness commented on GitHub (Aug 30, 2018):
I see …
/etc/resolver/devshould take care of this, though … I changed everything to.localhostand it’s still the same as before.@loilo commented on GitHub (Aug 30, 2018):
It should, in fact. However, at least Chrome did things with that TLD anyways (forcing all
.devon a HTTPS redirect for example) which is why at some point I switched to.localhost.Again, I don't think that should be an issue, but it's worth mentioning.
@loilo commented on GitHub (Sep 3, 2018):
Sooo... here's what I didn't realize:
I have in fact created a
*.localhostcertificate on my machine (as explained above), but it doesn't actually work. I dind't notice that because it was just one certificate among others, and the others worked.Now the difference is, that the others are not top level wildcard certificates but actually use subdomains of
localhost(such as*.web.localhost,*.public.localhostetc.)Wildcard certificates work for those, but not for
*.localhostbecause browsers don't support top level wildcard certificates for security reasons (mkcerteven warns you if you try to create such a certificate, shouldn't have ignored that).So, two ways to work around it:
[anything].dev.localhost. It's not pretty, but it allows you to omit any manual labor for certificates or server configuration.[anything].localhost), but you'll have to create a certificate and Apache configuration block whenever you want to use a new subdomain.Sorry for misleading you previously.
If you need help with adjusting the configurations to one of the mentioned approaches, feel free to hit me up here. :)
@fooness commented on GitHub (Sep 3, 2018):
Finally got it working with the suffix
.dev.localhost… thank you so much.I also read the warning in regards of wildcard certificates, it said
some browsersmight have problems if I remember correctly. Maybe it’s more than justsome…Really happy it’s properly working now!
@loilo commented on GitHub (Sep 3, 2018):
Nice, glad to hear that. If this is no longer an issue for you, I guess you could close this one. 🙂
@AndreKelling commented on GitHub (Jan 10, 2019):
https://github.com/FiloSottile/mkcert/issues/56#issuecomment-418075880
got it too...
so need to create like this
mkcert '*.dev.localhost'and notmkcert '*.localhost'@brimarq commented on GitHub (May 16, 2019):
FWIW, I have a macOS setup similar to @loilo with Homebrew httpd + dnsmasq using "automatic" virtual-hosts configuration. Instead of using a wildcard cert with a subdomain, I use a shell function in my
.bash_profilethat uses the directory names from my~/Sitesdirectory to create a SAN list for runningmkcert. This way, I can continue to use[project_dir].testinstead of[project_dir].[subdomain].test. Of course, I have to run the function again if I create a new project in~/Sites; but, like @loilo and @fooness , I prefer not having to use a subdomain unless I actually want one. This could always be expanded to create a new project dir in~/Sitesand then make new certs... lots of possibilities there.@FiloSottile, thanks for this handy tool!