skip to Main Content

I’m trying to put production shopware on a server and add a domain to it. The domain added to nginx, and here is my configuration.

server {

   server_name shopware.mydomain.com;

   location / {
      proxy_pass http://localhost:8085;
      proxy_hide_header X-Frame-Options;
      proxy_set_header  X-Real-IP   $remote_addr;   
      proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_hide_header Content-Security-Policy;
      proxy_hide_header X-Content-Type-Options;
      proxy_hide_header Referrer-Policy;
    }

    add_header Access-Control-Allow-Origin *;

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/shopware.domain.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/shopware.domain.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}
server {
    if ($host = shopware.mydomain.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


   listen 80;

   server_name shopware.mydomain.com;
    return 404; # managed by Certbot


}

Where let’s say "mydomain" is just my domain. Here is my /etc/hosts

127.0.0.1   localhost
91.205.75.138 199047.webh.me 199047

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

127.0.0.1 mydomain.com shopware.mydomain.com

I installed Shopware, but when I go into /admin, I get a JavaScript error caused by shopware trying to download js from http://localhost:8085 instead of the domain it is assigned. How do I get this to work properly?

2

Answers


  1. Chosen as BEST ANSWER

    For those who will have problems in the future. Shopware by default provides a docker image that includes nginx and php. In my case, there was an external nginx that handled the domain and SSL certificate, while this nginx inside the docker image overwrote my requests. So I split these images into smaller ones as follows:

    services:
      nginx:
        image: nginx:latest
        container_name: nginx
        restart: always
        ports:
          - 80:80
          - 443:443
        volumes:
          - ./nginx:/etc/nginx/conf.d
          - ./:/var/www/html
          - /etc/letsencrypt:/etc/nginx/ssl
        depends_on:
          - php
          - mysql
      php:
        build:
          context: .
          dockerfile: ./php-fpm/Dockerfile
        container_name: php
        restart: always
        volumes:
          - ./:/var/www/html
      mysql:
        image: mysql:8.0.25
        container_name: mysql
        restart: always
        environment:
          MYSQL_ROOT_PASSWORD: secret
          MYSQL_DATABASE: secret
          MYSQL_USER: secret
          MYSQL_PASSWORD: secret
        volumes:
          - /var/lib/mysql:/var/lib/mysql
      elasticsearch:
        image: docker.elastic.co/elasticsearch/elasticsearch:7.9.2
        container_name: elasticsearch
        restart: always
        environment:
          - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
          - discovery.type=single-node
    
        volumes:
          - ./elasticsearch:/usr/share/elasticsearch/data
        ports:
          - 9200:9200
    

    Dockerfile for php-fpm

    FROM php:8.1-fpm
    
    RUN apt-get update && apt-get install -y 
        libfreetype6-dev 
        libjpeg62-turbo-dev 
        libpng-dev 
        libzip-dev 
        zlib1g-dev 
        libicu-dev 
        && docker-php-ext-install -j$(nproc) iconv 
        && docker-php-ext-configure gd --with-freetype --with-jpeg 
        && docker-php-ext-install -j$(nproc) gd 
        && docker-php-ext-install -j$(nproc) pdo_mysql 
        && docker-php-ext-install -j$(nproc) zip 
        && docker-php-ext-install -j$(nproc) opcache 
        && docker-php-ext-install -j$(nproc) intl
    
    COPY ./php-fpm/php.ini /usr/local/etc/php/
    
    CMD ["php-fpm"]
    

  2. You should change the APP_URL variable in your .env file, which is located in the root directory of your Shopware 6 instance.

    # Change this url
    # In your .env File
    APP_URL="http://localhost:8085"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search