Bagisto Forum

    Bagisto

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    Nginx configuration for location with subfolder

    Installing Bagisto
    2
    2
    368
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      MIB1980 last edited by

      Hi community,

      I would like to install Bagisto with a docker stack and access this via subfolder of a Nginx location. I've already get it working with http://localhost (Storefront) and http://localhost/admin/ (Admin interface) but I would like to have it the following:

      Storefront: http://localhost/bagisto
      Admin interface: http://localhost/bagisto/admin

      I tried a lot but actually without success. Here is my current setup:

      Dockerfile

      # Use the official PHP image as a base image
      FROM php:8.1-fpm
      
      # Install system dependencies
      RUN apt-get update && apt-get install -y \
          git \
          curl \
          libpng-dev \
          libjpeg-dev \
          libfreetype6-dev \
          zip \
          unzip \
          libonig-dev \
          libxml2-dev \
          libzip-dev \
          ffmpeg \
          libicu-dev \
          libgmp-dev \
          libjpeg62-turbo-dev \
          libwebp-dev \
          libxpm-dev \
          zlib1g-dev \
          && docker-php-ext-configure gd --with-freetype --with-jpeg --with-webp \
          && docker-php-ext-configure intl \
          && docker-php-ext-install gd mbstring zip pdo pdo_mysql bcmath calendar exif gmp intl mysqli
      
      RUN pecl install xdebug && docker-php-ext-enable xdebug
      
      # Install Composer
      COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
      
      # Set working directory
      WORKDIR /var/www/html
      
      # Install Laravel dependencies
      RUN composer install
      
      # Copy existing application directory permissions
      RUN chown -R www-data:www-data /var/www/html/bagisto/storage /var/www/html/bagisto/bootstrap/cache
      RUN chmod -R 775 /var/www/html/bagisto/storage /var/www/html/bagisto/bootstrap/cache
      
      # Expose port 9000 and start php-fpm server
      EXPOSE 9000
      CMD ["php-fpm"]
      

      docker-compose.yml

      name: bagisto
      
      services:
        bagisto:
          build:
            context: .
            dockerfile: Dockerfile
          environment:
            - APP_DEBUG=true
          volumes:
            - ./bagisto:/var/www/html/bagisto
          depends_on:
            - mysql
            - redis
      
        redis:
          image: redis:alpine
          ports:
            - "6379:6379"
          volumes:
            - redis_data:/data
      
        mysql:
          image: mysql:8.0
          environment:
            MYSQL_ROOT_PASSWORD: root
            MYSQL_DATABASE: bagisto
            MYSQL_USER: bagisto
            MYSQL_PASSWORD: bagisto
          volumes:
            - mysql_data:/var/lib/mysql
            - ./_config/mysql-init:/docker-entrypoint-initdb.d
          ports:
            - "3310:3306"
      
        nginx:
          image: nginx:alpine
          command: [ nginx-debug, '-g', 'daemon off;' ]
          ports:
            - "80:80"
          volumes:
            - ./_config/nginx.conf:/etc/nginx/nginx.conf
            - ./_config/nginx-default.conf:/etc/nginx/conf.d/default.conf
            - ./bagisto:/var/www/html/bagisto
          depends_on:
            - bagisto
      
      networks:
        bagisto:
          name: bagisto
          driver: bridge
      
      volumes:
        bagisto_data:
          name: bagisto-data
        mysql_data:
          name: mysql-data
        redis_data:
          name: redis-data
      

      nginx-default.conf

      server {
          listen 80;
          server_name localhost;
          error_log /dev/stderr debug;
          root /var/www/html/bagisto/public;
          index index.php index.html index.htm;
      
          location /bagisto {
              alias /var/www/html/bagisto/public/;
              try_files $uri $uri/ /index.php?$query_string;
      
              location ~ ^/bagisto/(.*\.php(?:\?.*)?)$ {
                  include fastcgi_params;
                  fastcgi_pass bagisto:9000;
                  fastcgi_param SCRIPT_FILENAME $document_root$1;
              }
      
              location ~ /\.ht {
                  deny all;
              }
          }
      
          location /bagisto/admin {
                  alias /var/www/html/bagisto/public/;
                  try_files $uri $uri/ /index.php?$query_string;
      
                  location ~ ^/bagisto/admin/(.*\.php(?:\?.*)?)$ {
                      include fastcgi_params;
                      fastcgi_pass bagisto:9000;
                      fastcgi_param SCRIPT_FILENAME $document_root$1;
                  }
      
                  location ~ /\.ht {
                      deny all;
                  }
              }
      }
      

      Bagisto .env file

      APP_NAME=Bagisto
      APP_ENV=local
      APP_KEY=<MY KEY>
      APP_DEBUG=true
      APP_URL=http://localhost/bagisto
      APP_ADMIN_URL=admin
      APP_TIMEZONE=Europe/Berlin
      APP_LOCALE=en
      APP_CURRENCY=EUR
      
      LOG_CHANNEL=stack
      
      DB_CONNECTION=mysql
      DB_HOST=mysql
      DB_PORT=3306
      DB_DATABASE=bagisto
      DB_USERNAME=bagisto
      DB_PASSWORD=bagisto
      DB_PREFIX=
      
      BROADCAST_DRIVER=log
      CACHE_DRIVER=file
      SESSION_DRIVER=file
      SESSION_LIFETIME=120
      QUEUE_DRIVER=sync
      
      REDIS_HOST=bagisto-redis
      REDIS_PASSWORD=null
      REDIS_PORT=6379
      
      MAIL_MAILER=smtp
      MAIL_HOST=bagisto-mailhog
      MAIL_PORT=1025
      MAIL_USERNAME=null
      MAIL_PASSWORD=null
      MAIL_ENCRYPTION=null
      
      MAIL_FROM_ADDRESS=shop@example.com
      MAIL_FROM_NAME=Shop
      
      ADMIN_MAIL_ADDRESS=admin@example.com
      ADMIN_MAIL_NAME=Admin
      
      FIXER_API_KEY=
      EXCHANGE_RATES_API_KEY=c23c0af00d5b63af52c2d3971502a038
      
      PUSHER_APP_ID=
      PUSHER_APP_KEY=
      PUSHER_APP_SECRET=
      PUSHER_APP_CLUSTER=mt1
      
      MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
      MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
      
      FACEBOOK_CLIENT_ID=
      FACEBOOK_CLIENT_SECRET=
      FACEBOOK_CALLBACK_URL=https://yourhost.com/customer/social-login/facebook/callback
      
      TWITTER_CLIENT_ID=
      TWITTER_CLIENT_SECRET=
      TWITTER_CALLBACK_URL=https://yourhost.com/customer/social-login/twitter/callback
      
      GOOGLE_CLIENT_ID=
      GOOGLE_CLIENT_SECRET=
      GOOGLE_CALLBACK_URL=https://yourhost.com/customer/social-login/google/callback
      
      LINKEDIN_CLIENT_ID=
      LINKEDIN_CLIENT_SECRET=
      LINKEDIN_CALLBACK_URL=https://yourhost.com/customer/social-login/linkedin/callback
      
      GITHUB_CLIENT_ID=
      GITHUB_CLIENT_SECRET=
      GITHUB_CALLBACK_URL=https://yourhost.com/customer/social-login/github/callback
      
      ELASTICSEARCH_HOST=bagisto-elasticsearch
      

      The storefront is accessable via http://localhost/bagisto/ but when accessing http://localhost/bagisto/admin I get the storefront as well instead of having the admin interface displayed. Does anyone know what I am doing wrong?

      devansh-webkul 1 Reply Last reply Reply Quote 0
      • devansh-webkul
        devansh-webkul @MIB1980 last edited by

        @MIB1980,

        I don't think you need two extra configurations in the admin panel. You only need to adjust the Nginx configuration, and it will work. You can take reference from here as well:
        Laravel Nginx Deployment.

        1 Reply Last reply Reply Quote 0
        • First post
          Last post