When triyng to access website say domain.com
then it is giving 502 bad gateway error. I am using nginx server.
Structure of Project:
a) There is one Instance on google cloud on which nginx is hosted
b) There is another instance on which project code is deployed and it's ip is internal_ip_of_instance
and project is running on port 4400
Following is the nginx default file :
server {
listen 80;
server_name doman.com www.domain.com;
## redirect http to https ##
rewrite ^ https://$host$request_uri? permanent;
expires $expires;
}
# HTTPS Server
server {
listen 443 ssl;
server_name www.domain.com;
ssl_certificate /etc/letsencrypt/live/domain-0001/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/domain-0001/privkey.pem;
root /var/www;
index index.php index.html index.htm;
# Server-side CMS Redirect
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://internal_ip_of_instance:4400;
}
}
server {
listen 443 ssl;
server_name domain.com;
ssl_certificate /etc/letsencrypt/live/domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/domain.com/privkey.pem;
root /var/www;
index index.php index.html index.htm;
# Server-side CMS Redirect
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://internal_ip_of_instance:4400;
}
}
Code is deployed on instance of which ip is shown as internal_ip_of_instance
in above script. When project is referenced in above mentioned block as shown then when I am accessing domain.com
in the browser, it is giving 502 bad gateway error although all the APIs are being called successfully that are required to get data for that website.
But then created a new subdomain sub.domain.com
and added that in the nginx default file
server {
listen 80;
server_name sub.domain.com;
## redirect http to https ##
rewrite ^ https://$host$request_uri? permanent;
}
server {
listen 443 ssl;
server_name sub.domain.com;
ssl_certificate /etc/letsencrypt/live/domain.com-0001/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/domain.com-0001/privkey.pem;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://internal_ip_of_instance:4400;
}
}
Now when tried to access sub.domain.com
it is working fine and I am able to see data successfully. It means same project code is being used in both domain and subdomain block but from subdomain I am able to see all website content but using domain unable to do so although all the APIs are being called successfully that are required to get data for that website.
What is the problem? I think there is some problem in nginx default file's domain block.
2 days ago, everything was workng fine that means I was able to access the website using domain.com
but suddenly it started creating problem.
Please help.
Aucun commentaire:
Enregistrer un commentaire