Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

t9dev's avatar
Level 2

How to deploy a .NET 7 Web API and a Laravel Project on the same Ngnix Server?

We have a .NET Web API that is used to connect the database and a flutter application via HTTP, and to manage the data of the database we used Laravel 8 for the Admin Panel to perform CRUD actions, all of these are hosted in an Ubuntu server with Ngnix.

I have created two server blocks, one for the Laravel and the other is for the API.

API server block

    server {
    listen        80;
    server_name   _;
    root /var/www/API;
    location / {
    
        proxy_pass         http://localhost:8888;
        proxy_http_version 1.1;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_set_header   Connection keep-alive;
        proxy_set_header   Host $host;
        proxy_cache_bypass $http_upgrade;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;
    }   
}

Laravel Server Block

server {
    listen 80;
    server_name _;
    root /var/www/adminPanel/public;


    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";
    index index.php;
 
    location /{
    
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/run/php/php8.1-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
    location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
    expires 1y;
    add_header Cache-Control "public, no-transform";
    
    location ~ /\.(?!well-known).* {
        deny all;
    }
}
}

What I want to achieve is that the Laravel Admin Panel should be working on it's provided routes without interfering with the API that is running on URL 123.45.678.810/swagger/index.html . Currently, the Laravel Admin Panel is taking over the API, and when I change the server name to the default URL the API works, and when I set a location / both of them stops working.

0 likes
0 replies

Please or to participate in this conversation.