I am trying to deploy my angular app with a nginx server. The problem that i have is when i access to the website i need to be redirected to a specific location, in this case i need to be redirected to mydomain.com/shop, when i enter to this site it gets in a loop and start to type mydomain.com//shop/shop/shop/shop/shop......
Here is my code.
server {
listen 443 ssl;
ssl_certificate C:/nginx/ssl/cc.crt;
ssl_certificate_key C:/nginx/ssl/pkc.key;
server_name mydomain.com www.mydomain.com;
return 301 https://$host$request_uri/shop;
}
server {
listen 443 ssl;
client_max_body_size 200M;
ssl_certificate C:/nginx/ssl/cc.crt;
ssl_certificate_key C:/nginx/ssl/pkc.key;
server_name mydomain.com www.mydomain.com;
location / {
root html/myApp;
try_files $uri $uri/ /index.html;
}
location /api/ {
client_max_body_size 200M;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass https://127.0.0.1:4000/;
proxy_redirect off;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
how can i fix it? Thanks in advance
You have two server blocks with the same listen and server_name. The second block is being ignored as a duplicate.
You need to delete that first server block and place a redirection rule into the second block.
For example:
location = / {
return 301 /shop;
}