I have installed magento 2.4.2 and installation is done but when tried to access through url it shows 502 bad gateway error
502 Bad Gateway its a webserver error, so something are going wrong here. We need to know about its NGINX or Apache webserver you are running you Magento on.
In my case I have created a Docker setup to have all the pre-config for me when I developer Magento code.
I know there are a huge NGINX config file you need to take care of if you are running on NGINX webserver, if you are running Apache I can't help here sorry.
The next step I see when you have running the upgrade cli command, you need to get the right access to your project folder in my case becures its local I run it, I just give it
chmod -R 777 project/ if you are running on production
777 its not recommended.
But again when you hit 502 Bad Gateway there can be a lot of different errors here on you webserver access log.
Remember Magento required (PHP, MySQL and Elastic) to get up and running.