Cannot POST to /api location using nginx

Hey, everyone!

I have a site running on the 443 port using create-react-app and Express for the backend.

I have the following /etc/nginx/sites-enabled/default file

(Using to protect the privacy of my customers)

server {
    listen 80;
    return 301$request_uri;

server {
    listen 443 ssl;

    ssl_certificate /etc/letsencrypt/live/;
    ssl_certificate_key /etc/letsencrypt/live/;

    access_log /var/log/nginx/data-access.log combined;

    # serve the static files
    location / {
        root /home/developer_account/customer-management/customer-management-fe/build;
        try_files $uri /index.html;

    location /api/ {
        proxy_pass http://localhost:4000;

        proxy_ssl_session_reuse off;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
        proxy_redirect off;

When I hit the location under the / index works perfect (this is the react app)

However, when I hit or any other valid Express route, I get an error on the form:

Cannot POST /api/admins/login

When I ssh on my dropplet and use curl setting the proper params, and hit to http://localhost:4000/admins/login, it works perfect, including all the other Express routes I have!

I’m using pm2 (running without issues) and I’m not seeing any error on the pm2 service error.log

I’m using an Ubuntu 18.04 dropplet.

Could anyone point me on the right direction?

Thanks a lot!


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 @ricsasa201

I see that you use in your react app but you used http://localhost:4000/admins/login to test with curl. Is it a typo?