Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Thibaultvanc's avatar

laravel forge can accept both http https ?

Hello, A question for specialists ...

I have enabled the ssl certificate. But I need to use wilcard domain . I know that laravel forge cureently no supported to activate the wildcard automaically. But the question is :

is it possible to accept http://aaaa.laracast.com without the redirection to https (only for the domain different to www) ??

0 likes
13 replies
bashy's avatar

Just add another vhost server block for that wildcard (www. will match to the other server block).

Thibaultvanc's avatar

You mean in thé nginx files ? Could you provide an exemple please ?

bashy's avatar

Yes. server { }

Basically you have one server block for www. and another for the wildcard (no http->https redirect). You can use if but there's pitfalls. Just duplicate your www. site without the redirection.

Thibaultvanc's avatar

thank you Bashu for your patience I begin to understand the logic but I can't still make it running propely.

Here is my nginx config paste from Laravel forge (I have 3 blocks now ) :

server {
 listen 80;
 server_name mlm-valley.com;
 return 301 https://mlm-valley.com$request_uri;
}


server {
listen 80;
server_name *.mlm-valley.com;
return 301 http://aqw.mlm-valley.com$request_uri;
}


server {
listen 443 ssl;
server_name mlm-valley.com www.mlm-valley.com *.mlm-valley.com;
root /home/forge/mlm-valley.com/public;

# FORGE SSL (DO NOT REMOVE!)
ssl_certificate /etc/nginx/ssl/mlm-valley.com/53936/server.crt;
ssl_certificate_key /etc/nginx/ssl/mlm-valley.com/53936/server.key;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

index index.html index.htm index.php;

charset utf-8;

location / {
    try_files $uri $uri/ /index.php?$query_string;
}

location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt  { access_log off; log_not_found off; }

access_log off;
error_log  /var/log/nginx/mlm-valley.com-error.log error;

error_page 404 /index.php;

location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
}

location ~ /\.ht {
    deny all;
}

}

if i write in the browser : www.mlm-valley.com/ -> it's redirecting to https://mlm-valley.com/ I want it to redirect to https://www.mlm-valley.com/

if i write in the browser : test.mlm-valley.com/ -> it's redirecting to https://mlm-valley.com/ I want it to redirect to http://test.mlm-valley.com/

but

if i write in the browser : admin.mlm-valley.com/ -> it's redirecting to https://mlm-valley.com/ I want it to redirect to https://admin.mlm-valley.com/

Is a solution comes to your mind ?

bashy's avatar

That's not going to work, no.

server {
    listen 80;
    server_name mlm-valley.com;
    return 301 https://mlm-valley.com$request_uri;
}

server {
    listen 80;
    server_name admin.mlm-valley.com;

    return 301 https://admin.mlm-valley.com;
}

server {
    listen 80;
    server_name *.mlm-valley.com;
    
    # Surely you want an actual site for each sub domain here?
    return 301 http://aqw.mlm-valley.com$request_uri;
}

server {
    listen 443 ssl;

    # This is picking up admin. and any other HTTPS sub domain.
    server_name mlm-valley.com www.mlm-valley.com *.mlm-valley.com;

    [...]
}
Thibaultvanc's avatar

you're a genius ! it's working.

But as you write n comment, the wildcard is redirecting to http://aqw.mlm-valley.com$request_uri;

how can I set the redirection to it's domain (*) ?

I know it's not going to work but somethig like :

server {
listen 80;
server_name *.mlm-valley.com;

return 301 http://{*}.mlm-valley.com$request_uri;   ##########
}
bashy's avatar

You can redirect to the requested host?

return 301 http://$server_name$request_uri;
bashy's avatar
bashy
Best Answer
Level 65

Probably need this then. Sorry $server_name was wrong.

return 301 http://$host$request_uri;
hannasdeli's avatar

I was facing a similar problem (needed to serve both http and https) and I was going crazy because nothing seemed to work in a forge managed server in Digital Ocean. This thread was probably the most helpful.

The issue was that no matter what nginx config my pages were all redirected to https and I needed (for some very specific reasons) to serve both http and https.

It turns out the issue was that in Forge nginx config files include some lines like this one:

include forge-conf/testsite.co.uk/before/*;

That include prepends a file generated by forge that has an entry like this

server {
    listen 80;
    listen [::]:80;

    server_name .example.site.co.uk;
    return 301 https://$host$request_uri;
}

Just ssh to your server, go to the nginx config folder, and then you will find a forge-conf and some folders for your domains... and just comment those lines. Now your nginx can serve both http and https without forcing the redirect.

I was going MENTAL with this and unfortunately not much help from the forge support channel.

3 likes
javeed_rahman's avatar

Hi, @bashy @hannasdeli

I have the same problem, I want to load my site in both HTTP and https

my config under forge-config/example.com/before/*

server {
    listen 80;
    listen [::]:80;

    server_name .test.example.com;
    return 301 http://test.example.com$request_uri;
}

# Redirect SSL to primary domain SSL...
server {
        listen 443 ssl http2;
    listen [::]:443 ssl http2;

    # FORGE SSL (DO NOT REMOVE!)
    ssl_certificate .....
    .......
    .......

    server_name www.test.example.com;
    return 301 https://test.example.com$request_uri;
}

Here, when I load with https it is loading the page but when I load with HTTP it is showing TOO MANY REDIRECTS I have cleared browser history and cookie and cache no luck.

Please help

bashy's avatar

@javeed_rahman You're redirecting on both server blocks... that's why it's redirecting over and over.

Just serve the site with one server block and add listen 80; to the same block. If it hits on port 80, it will ignore all the SSL stuff.

NAM's avatar

Would altering the forge-config/example.com/before/* scripts be problematic? Don't they automatically get updated whenever SSL certificates are requested/renewed?

I too want to allow for both http and https, but forge assumes we always only ever want https.

UPDATE: If anyone is looking for the path to the config files, it's here: "/etc/nginx/forge-conf/"

Please or to participate in this conversation.