Setup a subdomain with nginx but always redirected to top domain

I wanna set up my subdomain but it keeps redirected to my top domain, i’ve read alot of threads about this. but none of them worked for me this is my subdomain conf file

server {
	listen 80;

	root /var/www/laravel/public;
	index index.php index.html index.htm index.nginx-debian.html;

	location / {
		# try_files $uri $uri/ =404;
		try_files $uri $uri/ /index.php?$query_string =404;

	location ~ \.php$ {
		include snippets/fastcgi-php.conf;
		fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
	#	# With php-cgi (or other tcp sockets):
	#	fastcgi_pass;

	location ~ /\.ht {
		deny all;

And ofc I have linked it in sites-enabled, should I add my subdomain to /etc/hosts? if i should, i have but still doesn’t work.

Also, i’m using cloudflare if this has a concern I hope you can help me to solve this, Thanks in advance


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi @fikal1410,

Thanks for the anwser!

Okay, let’s go for the next possibilities. Is your subdomain using it’s own separate database than the main subdomain? And one more thing, can you confirm if the main and subdomain were installed manually and you didn’t copy the files from the main domain to the subdomain?

Hi @fikal1410,

I can see you are using the following root directory:

    root /var/www/laravel/public;

Is that the Directory of your main or subdomain? I’m asking as this be the source of your issues.

Additionally, I take it you have created two separated configs for both the main and the subdomain as well, correct?

Regards, KFSys