Require 'www' for

António P. P. Almeida appa at
Sat Mar 23 03:01:35 UTC 2013

On 22 Mar 2013 23h44 CET, nginx-forum at wrote:

> I am setting up a server that will be for a B2B business, and I want
> the whole site to be served as
> I have gotten a certificate and runs just
> fine, but I can't figure out how to require
> when a user tries to go to
> In reading through the site, it seems like rewrites and if
> statements are discouraged. I did figure out how to require
> by using the following in my server block
> file:
> server {
> listen [::]:80;
> server_name *;
> return 301 $scheme://$request_uri;
> }
> But doing something similar for 443 doesn't seem to work.

It works, but you have to add the SSL certificate and respective
key. Note that the root domain must be also in the certificate
otherwise the client will complain about the certificate, not being
able to establish endpoint authentication.

> Can someone please help me out or point to a good page on setting up
> for this?

Here's an example. It rewrites from www to the base domain. So just
switch the server names and it will work. Add also a listen directive
for port 80.

--- appa

More information about the nginx mailing list