Saturday, March 03, 2018

Re: httpd howto redirect port 80 to 443 in vm

hi everyone


On 02/03/2018 18:45, contact - ulysse lab wrote:
> Put into /etc/httpd.conf :
>
> types { include "/usr/share/misc/mime.types" }
>
> server "default" {
>
>         listen on * tls port 443
>         tls certificate "/etc/letsencrypt/live/example.com/fullchain.pem"
>         tls key "/etc/letsencrypt/live/example.com/privkey.pem"
>
>         root "/htdocs/example.com"
>
> }
>
> server "www.example.com" {
>
>         alias "example.com"
>
>         listen on * port 80
>         block return 301 "https://$SERVER_NAME$REQUEST_URI"
>
> }
>
> Le 02/03/2018 à 15:51, Base Pr1me a écrit :
>> I simply have a block in my httpd.conf for my redirects:
>>
>> server "example.com" {
>>          listen on $ext_if port 80
>>          alias "www.example.com"
>>          block return 301 "https://example.com/"
>> }
>>
>> On Fri, Mar 2, 2018 at 7:40 AM, Solène Rapenne <solene@perso.pw> wrote:
>>
>>> Le 2018-03-02 15:33, Matt M a écrit :
>>>
>>>> Why not use a .htaccess redirect?
>>>>
>>>> https://www.sslshopper.com/apache-redirect-http-to-https.html
>>>>
>>> .htaccess file is a feature of Apache web server while we are
>>> talking about httpd.
>>>
>>>
>
thanks for all the help
as i was just getting my feet wet with vmm
i hadn't setup a domainname in dns for the host
i was simply accessing the host machine via an ip address.
i modified the above example with the ip address of the host and
redirection worked perfectly

my httpd.conf

# $OpenBSD: httpd.conf,v 1.17 2017/04/16 08:50:49 ajacoutot Exp $

#
# Macros
#
ext_addr="*"
#
# Global Options
#
# prefork 3
#
# Servers
#
# A minimal default server
server "default" {
        listen on $ext_addr tls port 443
        tls {
                key "/etc/ssl/private/server.key"
                certificate "/etc/ssl/server.crt"
        }
        directory {
                index "index.php"
        }
        location "*.php" {
                fastcgi socket "/run/php-fpm.sock"
        }
}

server "host server ip address" {
        listen on * port 80
        block return 301 "https://$SERVER_NAME$REQUEST_URI"
}

# Include MIME types instead of the built-in ones
types {
        include "/usr/share/misc/mime.types"
}

#---------------------------------------------------------------------------------------

shadrock

No comments:

Post a Comment