yaswanthgupta's avatar

yaswanthgupta wrote a reply+100 XP

3mos ago

I have revised my setup. I am hosting the site in nginx using port 8001.

Here are my files. I will describe the issue at the end of the files.

nginx.conf file

.env file

APP_URL=http://server_ip:8000/APGBDOS
ASSET_URL=http://server_ip:8000/APGBDOS

vite.config.ts file

AppServiceProvider.php file boot method

    public function boot(): void
    {
        // If APP_URL is set in .env, force Laravel to use it as the root
        if (config('app.url')) {
            URL::forceRootUrl(config('app.url'));
        }

        // Handle X-Forwarded-Prefix header from nginx
        if ($prefix = request()->header('X-Forwarded-Prefix')) {
            // This ensures Laravel knows about the prefix
            request()->server->set('SCRIPT_NAME', $prefix . '/index.php');
        }

part of login.tsx file

import login from "@/routes/login";

    post(login.store.url(), {
      onFinish: () => reset("password")
    });

Issue:

As my AppServiceProvider.php file has URL::forceRootUrl(config('app.url'));, wayfinder is generating absolute urls instead of relative urls. Because of this, I get this error in console while submitting the login form (observe there is double http).

POST http://http//server_ip:8000/APGBDOS/login net::ERR_NAME_NOT_RESOLVED

If I remove URL::forceRootUrl(config('app.url')); in AppServiceProvider.php file making the wayfinder to generate relative paths. I get this error

404 Not Found nginx/1.28.0

For Reference:

part of resources\js\routes\login\index.ts file BEFORE adding URL::forceRootUrl(config('app.url')); in AppServiceProvider.php file

store.definition = {
    methods: ["post"],
    url: '/login',
} satisfies RouteDefinition<["post"]>

/**
* @see \Laravel\Fortify\Http\Controllers\AuthenticatedSessionController::store
 * @see vendor/laravel/fortify/src/Http/Controllers/AuthenticatedSessionController.php:58
 * @route '/login'
 */
store.url = (options?: RouteQueryOptions) => {
    return store.definition.url + queryParams(options)
}

part of resources\js\routes\login\index.ts file AFTER adding URL::forceRootUrl(config('app.url')); in AppServiceProvider.php file

store.definition = {
    methods: ["post"],
    url: '//http://server_ip:8000/APGBDOS/login',
} satisfies RouteDefinition<["post"]>

/**
* @see \Laravel\Fortify\Http\Controllers\AuthenticatedSessionController::store
 * @see vendor/laravel/fortify/src/Http/Controllers/AuthenticatedSessionController.php:58
 * @route '//http://server_ip:8000/APGBDOS/login'
 */
store.url = (options?: RouteQueryOptions) => {
    return store.definition.url + queryParams(options)
}
yaswanthgupta's avatar

yaswanthgupta started a new conversation+100 XP

4mos ago

My Setup

  • Laravel React Starter Kit hosted on IIS (Port 81)
  • Nginx running on Port 8000

Configuration Details

Nginx

  • A location block is configured with proxy_pass pointing to port 81

  • When a user visits, http://server_ip:8000/app1 it proxies to http://server_ip:81/app1

Vite - vite.config.js

base: '/app1/'

Laravel - bootstrap/app.php

->withMiddleware(function (Middleware  $middleware) {
$middleware->trustProxies(at: '*');

Laravel - .env

APP_URL=http://server_ip:8000/app1 ASSET_URL=http://server_ip:8000/app1

Issue

I am able to access the site via http://server_ip:8000/app1 but the URL automatically goes back to http://server_ip:8000/ . Now I cannot login not i cannot just refresh the browser because the app is in http://server_ip:8000/app1

I have also tried in multiple ways like proxying through IIS also (without Nginx). Here also, I face the same issue.

Kindly help me out !