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

JoaquinVilchez's avatar

App works in domain.com but not in www.domain.com

Hello!

I am uploading my application to digitalocean for the first time and I am having the problem that when I enter my application by typing pedisimple.com it works perfectly, but when I enter www.pedisimple.com it returns a 404 error ...

I have the records as they should be: Record A => pedisimple.com pointing to the server IP CNAME record => www.pedisimple.com pointing to pedisimple.com

I ran the ping command in my terminal of the two domains and they both work perfectly and point to the same IP ... So I thought it might be a problem with my application developed in laravel.

In my .env I have APP_URL = www.pedisimple.com

Does anyone know what it could be?

0 likes
29 replies
MarianoMoreyra's avatar

Hi @joaquinvilchez

The 404 it’s returned from Laravel or from the web server?

Because maybe you need to configure Apache to serve both the www and the non-www versions.

1 like
JoaquinVilchez's avatar

Hello! The 404 error is from nginx ... but I thought that maybe some configuration was missing on my server to redirect and to correctly search the files when I enter www.pedisimple.com

Thank you very much for the article, I will read it and try to follow the steps.

JoaquinVilchez's avatar

Hola Mariano! No sabia que eras de Buenos Aires! Un gusto conocerte. Segui la guia que me pasaste pero no logro solucionarlo... es raro porque yo genere el certificado SSL con certbot y despues de eso mi archivo en /etc/nginx/sites-enabled/pedisimple cambio y tiene mas cosas que desconozco y que nose si estoy ubicando bien el codigo que me dice la guia... Nose si ese archivo se puede mostrar al publico para que lo vean o es privado...

Despues de configurar si corro curl -I https://www.pedisimple.com me muestra lo siguiente:

HTTP/1.1 404 Not Found
Server: nginx/1.18.0 (Ubuntu)
Date: Wed, 23 Dec 2020 14:17:25 GMT
Content-Type: text/html
Content-Length: 162
Connection: keep-alive

Aclaro que soy nuevo en esto de los servidores...

Gracias por la ayuda.

MarianoMoreyra's avatar

@joaquinvilchez Un gusto conocerte también Joaquín! Sigo en inglés (aunque mi inglés no sea tan bueno) más que nada por el resto del foro, así otros pueden opinar / ayudar.

The thing is that I see that now it's not working neither for https://pedisimple.com nor https://www.pedisimple.com

Probably something went wrong with the ssl configuration?

I believe there's nothing wrong with sharing your ngix configuration, as long as you change any sensible information with generic data.

I don't have that much experience with ngix particularly but maybe I can help anyway, or someone else with more ngix experience might spot the problem right away!

JoaquinVilchez's avatar

Yes! when I change the configuration as the article you gave me tells me that happens to me ... instead if I leave the servername as pedisimple.com instead of www.pedisimple.com it works again (Only for when I enter without www) ... it's weird and I'm not really into it to be able to fix it.

When I did the SSL I remember that I followed an article and I did it with the following command indicating the two domains:

sudo certbot --nginx -d pedisimple.com -d www.pedisimple.com

I help myself with this video: https://www.youtube.com/watch?v=HBsCuZlDg60

I show you my configuration file: https://ibb.co/fDGsqZb

Thank You.

MarianoMoreyra's avatar

@joaquinvilchez this is the nginx configuration file that you are using right now, when https://pedisimple.com is working?

If that's the case, try this.

Change the last server block to this:

server {
    listen 80;
    server_name www.pedisimple.com pedisimple.com;
    return 301 $scheme://pedisimple.com$request_uri;
}

This should make http://pedisimple.com and http://www.pedisimple.com redirect to https://pedisimple.com

Let's start with this, and if it works, we can move on to make the last redirection work (www with ssl to non-www with ssl)

Please remember to restar NGINX after these changes

JoaquinVilchez's avatar

No Mariano, unfortunately it doesn't work. I appreciate your concern but there is no way... I read all the forums and I have been with this for weeks.

What I find strange is that it is not a problem like a "This site can't be rached" or something like that, but it is a 404 error... like it cannot find the /public folder of my project when entering with www.

I tried adding root /var/www/pedisimple/public to it but it didn't work either...

MarianoMoreyra's avatar

@joaquinvilchez the 404 error happens because you have some rules on your configuration file that tell to reply with that error.

Also, it's not that your server it's not reachable, but it just not pointing to where it should for your subdomains.

Currently, I see that the redirection is correctly working for the non-ssl & non-www version. So right now, if you browse to https://pedisimple.com it works, and if you browse http://pedisimple.com it's redirecting to the SSL version and it works too!

If you want, please share the config file as it is right now, so I can see if I can spot the problem.

Hope you can get to solve this!

JoaquinVilchez's avatar

Thanks Mariano. Yes, I understand what you are saying ... but it is hard for me to find the solution.

I show you the configuration file that is at this moment.

    server_name pedisimple.com;
    root /var/www/pedisimple/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    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; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/pedisimple.com-0001/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/pedisimple.com-0001/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

server {
    listen 80;
    server_name www.pedisimple.com pedisimple.com;
    root /var/www/pedisimple/public;
    return 301 https://pedisimple.com$request_uri;
}

And if it works for you too, these are the DNS records that I configure:

; <<>> DiG 9.16.1-Ubuntu <<>> www.pedisimple.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 11362
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;www.pedisimple.com.            IN      A

;; ANSWER SECTION:
www.pedisimple.com.     3599    IN      A       198.199.91.10

;; Query time: 23 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Sun Dec 27 02:06:53 UTC 2020
;; MSG SIZE  rcvd: 63
MarianoMoreyra's avatar

It's really weird @joaquinvilchez

It almost seems like it was using a different config file (or even the original one that you posted).

Just one more test...add the www. domain to the ssl server block so it says:

server_name pedisimple.com www.pedisimple.com;

As I see that you've configured ssl certificates for both domains, and now the non-ssl version of the www. is redirecting to the ssl version, mantaining the www.

So, if you add that to the 443 server block, maybe it will finally work for all versions

As always, remember to reload the NGINX service (by the way...how are you reloading the service?)

JoaquinVilchez's avatar

No, there I iterate again and it still doesn't work... if once the configuration file has been changed I execute: sudo nginx -s reload and it returns the following warning:

nginx: [warn] conflicting server name "www.pedisimple.com" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "www.pedisimple.com" on 0.0.0.0:443, ignored

I'll see what I do, I'll continue investigating on my own. A shame because it took many months of work to get stuck with this! but hey, that's how you learn too.

Thanks @marianomoreyra for everything.

MarianoMoreyra's avatar

OK @joaquinvilchez

I hope you get to solve it!

One last contribution...check this comment on a StackOverflow question:

Certbot from LetsEncrypt had added a server block in the default file in my case. It did that cause I tried to get the certificate before I had setup the separate server block

Maybe you had the same problem when you run Certbot?

Also, the accepted answer on that same post has another interesting theory to wath out.

This is the post: https://stackoverflow.com/questions/11426087/nginx-error-conflicting-server-name-ignored

Hope this works for you! In case you keep struggling with this in a couple of days, feel free to contact me so we can try to solve it over Team Viewer if you are ok.

Wish you best of the lucks!

JoaquinVilchez's avatar

Thanks Mariano, I was reading what you happened to me and yes, I had some duplicate files that I could delete. But it did not solve my problem.

Anyway, thanks to that I realized something that may help to solve the problem.

I noticed that in /etc/nignx/sites-available I have 3 files:

default digitalocean pedisimple

Always the configurations that you recommended me to do, I did them in pedisimple and it only worked with pedisimple.com. But curiously, I went in and modified the digitalocean and I could not solve it, but I saw changes when entering through www.pedisimple.com... now instead of a 404 error it gave me a 403 error So, as I understand it, that is the file that is affecting...

What I thought is that it may be a certbot error with the SSL certification and it was configured within that directory and not in the one of pedisimple, but I'm not sure.

My question is if you can completely delete the SSL certificate and the default and digitalocean files to regenerate the certificate and do it in the correct folder, if that is the possible error.

Any files they need I pass them on.

Thanks a lot

JoaquinVilchez's avatar

Hi Mariano! Thank you so much for your help. I tryed everything but doesnt fix a this way... but i fixed! i removed the droplet and start again... the problem was in SSL certificate. The configuration was in different folders and broken it.

Thank you so much for your help.

JoaquinVilchez's avatar

Yes, I tried and it doesn't work either... Before I had an A record with pedisimple.com and a CNAME that was pointed to pedisimple.com... and now I only put two A records as you told me but the same error still persists.

siangboon's avatar

do a simple test to narrow down the problem cause first by simply adding a html file on the document root folder and browse it... if you cant view it mean server side configuration issue...

munazzil's avatar

Just check with this because if your using https that caused mostly error,

   APP_URL =https://www.pedisimple.com

if your are using http then use below and check,

   APP_URL = http://www.pedisimple.com
1 like
sr57's avatar

Did you test with by replacing CNAME record by A record as I suggest in my previous post?

JoaquinVilchez's avatar

I am trying every answer they told me. As I do them I answer!

sr57's avatar

I see no answer to remove CNAME!

ousid's avatar

Have you tried to add the A Record?

Please or to participate in this conversation.