2

I don't know this is off-topic or not, But I need to know magento2 have any port forwarding restrictions,

Because, I have setup port concepts in docker to access my container magento2 to locally connected another system.

This is Docker Container Setup:

docker run -it -d --name containerName -h www.myhost.net -v /var/www/html -p 3000:80 --net mynetwork --ip 172.11.0.10 --privileged myimagename 

Then, Execute the Container:

docker exec -it containerName bin/bash

volume path /var/www/html with in the volume path i write one index.html file and access to another locally connected system its working fine.

hostmachineip:3000

After I installed magnento2 in my container with in volume(/var/www/html)

Then access magento 2 to another locally connected system thats redirect this magento 2 url but say Aborted and show blank page.

hostmachineip:3000

Reference:

enter image description here

But: if I call host machine its working file,

 hostmachineip:3000  

Its redirect to right server, show magento2 home page.

remote machine only not working.

My Configuration Files:

Loadbalancer Machine Conf file:

    upstream backend {
       ip_hash;
       server 172.11.0.10 weight=5;
       server 172.11.0.20 weight=2;

    }


    server {
        listen 80;
        server_name  myhost.net  www.myhost.net;

       location / {

        proxy_pass http://backend;
        include /etc/nginx/proxy_params;

         }

    location ~* \.(js|css|jpg|jpeg|gif|png|svg|ico|pdf|html|htm)$ {
        }

     }

include /etc/nginx/proxy_params File:

    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    client_max_body_size 100M;
    client_body_buffer_size 1m;
    proxy_intercept_errors on;
    proxy_buffering on;
    proxy_buffer_size 128k;
    proxy_buffers 256 16k;
    proxy_busy_buffers_size 256k;
    proxy_temp_file_write_size 256k;
    proxy_max_temp_file_size 0;
    proxy_read_timeout 300;

Server 1 Configuration File: /etc/nginx/site-available/default (server 172.11.0.10)

  # nginx + magento2 server configuration 

    server {
        listen 80;
        listen [::]:3000;

        server_name www.myhost.net  myhost.net;

        access_log /var/log/nginx/access_log;
        error_log  /var/log/nginx/error_log;


        root  /var/www/html;

        location / {
        index index.html index.php;
        try_files $uri $uri/ @handler;
        }

        # Deny access to specific directories no one
        # in particular needs access to anyways.
        location /app/ { deny all; }
        location /includes/ { deny all; }
        location /lib/ { deny all; }
        location /media/downloadable/ { deny all; }
        location /pkginfo/ { deny all; }
        location /report/config.xml { deny all; }
        location /var/ { deny all; }

        # Allow only those who have a login name and password
        # to view the export folder. Refer to /etc/nginx/htpassword.

        location /var/export/ {
        auth_basic "Restricted";
        auth_basic_user_file htpasswd;
        autoindex on;
        }

        # Deny all attempts to access hidden files
        # such as .htaccess, .htpasswd, etc...

        location ~ /\. {
         deny all;
         access_log off;
         log_not_found off;
        }

        # This redirect is added so to use Magentos
        # common front handler when handling incoming URLs.

        location @handler {
        rewrite / /index.php;
        }

        # Forward paths such as /js/index.php/x.js
        # to their relevant handler.

        location ~ .php/ {
        rewrite ^(.*.php)/ $1 last;
        }

       # pass the PHP scripts to FPM socket

       location ~ \.php$ {
        try_files $uri =404;

        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param DOCUMENT_ROOT /var/www/html;
        fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;

        #send bad requests to 404
        fastcgi_intercept_errors on;

         include fastcgi_params;
    }
    }

Update 1:

Now, Port forwarding working based on blow i Posted answer, But view without css and images. But if I call host machine it calling all css and images and working fine.

Remote machine only doesn't call CSS and Images.

While I Test Port forwarding in remote machine, get contents form hostmachine, but remote machine check images and css with in machine not a host machine. That is what this problem occur.

I tried This Configuration also: But Still have same problem.

  upstream fastcgi_backend {
       server  unix:/run/php/php7.0-fpm.sock;
    }
    server {
       listen 80;
       server_name www.myhost.net myhost.net;

       set $MAGE_ROOT /var/www/html;
       set $MAGE_MODE developer;
       include /var/www/html/nginx.conf.sample;
    }

nginx.conf.sample Configuration File:

      root $MAGE_ROOT;

        index index.php;
        autoindex off;
        charset off;

        add_header 'X-Content-Type-Options' 'nosniff';
        add_header 'X-XSS-Protection' '1; mode=block';

        location /setup {
            root $MAGE_ROOT;
            location ~ ^/setup/index.php {
                fastcgi_pass   fastcgi_backend;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
            }

            location ~ ^/setup/(?!pub/). {
                allow all;
            }

            location ~ ^/setup/pub/ {
                add_header X-Frame-Options "SAMEORIGIN";
            }
        }

        location /update {
            root $MAGE_ROOT;
            location ~ ^/update/index.php {
                fastcgi_split_path_info ^(/update/index.php)(/.+)$;
                fastcgi_pass   fastcgi_backend;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                fastcgi_param  PATH_INFO        $fastcgi_path_info;
                include        fastcgi_params;
            }

            # deny everything but index.php
            location ~ ^/update/(?!pub/). {
                allow all;
            }

            location ~ ^/update/pub/ {
                add_header X-Frame-Options "SAMEORIGIN";
            }
        }

        location / {
            try_files $uri $uri/ /index.php?$args;
        }

        location /pub {
            location ~ ^/pub/media/(downloadable|customer|import|theme_customization/.*\.xml) {
                allow all;
            }
            alias $MAGE_ROOT/pub;
            add_header X-Frame-Options "SAMEORIGIN";
        }

        location /static/ {
            if ($MAGE_MODE = "production") {
                expires max;
            }
            location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
                add_header Cache-Control "public";
                add_header X-Frame-Options "SAMEORIGIN";
                expires +1y;

                if (!-f $request_filename) {
                    rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
                }
            }
            location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
                add_header Cache-Control "no-store";
                add_header X-Frame-Options "SAMEORIGIN";
                expires    off;

                if (!-f $request_filename) {
                   rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
                }
            }
            if (!-f $request_filename) {
                rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
            }
           add_header X-Frame-Options "SAMEORIGIN";
        }

        location /media/ {
            try_files $uri $uri/ /get.php?$args;

            location ~ ^/media/theme_customization/.*\.xml {
                allow all;
            }

            location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
                add_header Cache-Control "public";
                add_header X-Frame-Options "SAMEORIGIN";
                expires +1y;
                try_files $uri $uri/ /get.php?$args;
            }
            location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
                add_header Cache-Control "no-store";
                add_header X-Frame-Options "SAMEORIGIN";
                expires    off;
                try_files $uri $uri/ /get.php?$args;
            }
            add_header X-Frame-Options "SAMEORIGIN";
        }

        location /media/customer/ {
            deny all;
        }

        location /media/downloadable/ {
            deny all;
        }

        location /media/import/ {
            deny all;
        }

        location ~ cron\.php {
            deny all;
        }

        location ~ (index|get|static|report|404|503)\.php$ {
            try_files $uri =404;
            fastcgi_pass   fastcgi_backend;

            fastcgi_param  PHP_FLAG  "session.auto_start=off \n suhosin.session.cryptua=off";
            fastcgi_param  PHP_VALUE "memory_limit=256M \n max_execution_time=600";
            fastcgi_read_timeout 600s;
            fastcgi_connect_timeout 600s;
            fastcgi_param  MAGE_MODE $MAGE_MODE;

            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

if I install magento 2 with port

For example:

   myhost.com:3000/

Now, occur reverse problem, remote machine working fine, host-machine doesn't call css and images.

Update 2:

Do you set the base_url?

  Yes , I set BaseUrl (www.myhost.com)

What Magento version are you using?

    I use Magento Version 2.0.8 

Retrun Html page Looks Like:

enter image description here

what the URL to the CSS etc files?

    While port forwarding Css and all other static contents goes to 404 page

reference:

enter image description here Are they coming back correct?

 No, while click css path, goes to 404 page.

Can you open the CSS file in a web browser and download them?

    I cannot download css file in a webbrowser.

Reference Info:

loadbalancer docker:

I have create docker with portforwarding using port 3000 and nginx loadbalancer

  IP: 172.17.0.2

  docker run -it -d  -h www.myhost.net -v /var/www/html/ --privileged -p 3000:80  --name containername1   remoteserver11 

magento machine:

I have installed nginx + Magento with portforwarding using port 3001.

 IP: 172.17.0.4
 Hostname: www.myhost.net
 magento baseurl:www.myhost.net

    docker run -it -d  -h www.myhost.net -v /var/www/html/ --privileged -p 3001:80  --name containername2   remoteserver11 

LoadBalancer Machine Configuration:

    upstream backend {
       ip_hash;
       server 172.17.0.4;
    }

    server {
        listen 80;
        server_name  myhost.net  www.myhost.net;

        location / {
            proxy_pass http://backend;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;

        }

Magento Machine Configuration:

    upstream fastcgi_backend {
       server  unix:/run/php/php7.0-fpm.sock;
    }
    server {
       listen 80;
       server_name www.myhost.net  myhost.net;

       set $MAGE_ROOT /var/www/html;
       set $MAGE_MODE developer;
       include /var/www/html/nginx.conf.sample;
    }

include /var/www/html/nginx.conf.sample;

               root $MAGE_ROOT/pub;

                index index.php;
                autoindex off;
                charset off;

                add_header 'X-Content-Type-Options' 'nosniff';
                add_header 'X-XSS-Protection' '1; mode=block';

                location /setup {
                    root $MAGE_ROOT;
                    location ~ ^/setup/index.php {
                        fastcgi_pass   fastcgi_backend;
                        fastcgi_index  index.php;
                        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                        include        fastcgi_params;
                    }

                    location ~ ^/setup/(?!pub/). {
                        allow all;
                    }

                    location ~ ^/setup/pub/ {
                        add_header X-Frame-Options "SAMEORIGIN";
                    }
                }

                location /update {
                    root $MAGE_ROOT;
                    location ~ ^/update/index.php {
                        fastcgi_split_path_info ^(/update/index.php)(/.+)$;
                        fastcgi_pass   fastcgi_backend;
                        fastcgi_index  index.php;
                        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                        fastcgi_param  PATH_INFO        $fastcgi_path_info;
                        include        fastcgi_params;
                    }

                    # deny everything but index.php
                    location ~ ^/update/(?!pub/). {
                        allow all;
                    }

                    location ~ ^/update/pub/ {
                        add_header X-Frame-Options "SAMEORIGIN";
                    }
                }

                location / {
                    try_files $uri $uri/ /index.php?$args;
                }

                location /pub {
                    location ~ ^/pub/media/(downloadable|customer|import|theme_customization/.*\.xml) {
                        allow all;
                    }
                    alias $MAGE_ROOT/pub;
                    add_header X-Frame-Options "SAMEORIGIN";
                }

                location /static/ {
                    if ($MAGE_MODE = "production") {
                        expires max;
                    }
                    location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
                        add_header Cache-Control "public";
                        add_header X-Frame-Options "SAMEORIGIN";
                        expires +1y;

                        if (!-f $request_filename) {
                            rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
                        }
                    }
                    location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
                        add_header Cache-Control "no-store";
                        add_header X-Frame-Options "SAMEORIGIN";
                        expires    off;

                        if (!-f $request_filename) {
                           rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
                        }
                    }
                    if (!-f $request_filename) {
                        rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
                    }
                   add_header X-Frame-Options "SAMEORIGIN";
                }

                location /media/ {
                    try_files $uri $uri/ /get.php?$args;

                    location ~ ^/media/theme_customization/.*\.xml {
                        allow all;
                    }

                    location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
                        add_header Cache-Control "public";
                        add_header X-Frame-Options "SAMEORIGIN";
                        expires +1y;
                        try_files $uri $uri/ /get.php?$args;
                    }
                    location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
                        add_header Cache-Control "no-store";
                        add_header X-Frame-Options "SAMEORIGIN";
                        expires    off;
                        try_files $uri $uri/ /get.php?$args;
                    }
                    add_header X-Frame-Options "SAMEORIGIN";
                }

                location /media/customer/ {
                    deny all;
                }

                location /media/downloadable/ {
                    deny all;
                }

                location /media/import/ {
                    deny all;
                }

                location ~ cron\.php {
                    deny all;
                }

                location ~ (index|get|static|report|404|503)\.php$ {
                    try_files $uri =404;
                    fastcgi_pass   fastcgi_backend;

                    fastcgi_param  PHP_FLAG  "session.auto_start=off \n suhosin.session.cryptua=off";
                    fastcgi_param  PHP_VALUE "memory_limit=256M \n max_execution_time=600";
                    fastcgi_read_timeout 600s;
                    fastcgi_connect_timeout 600s;
                    fastcgi_param  MAGE_MODE $MAGE_MODE;

                    fastcgi_index  index.php;
                    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                    include        fastcgi_params;
                }

After Install magento2, I working fine in host machine calling magento base Url

Port Forwarding Configuration:

   Hostmachine ip: 192.168.1.10
   Remotemachine ip: 192.168.1.12

I added Loadbanacer Docker ip to hostmachine /etc/hosts

   172.17.0.2   www.myhost.com

then, Add host machine ip to remote machine /etc/hosts

   192.168.1.10  www.myhost.com

After call magento 2 using port forwarding in remote machine from hostmachine

     192.168.1.10:3000

Its only show with out css an all other static content, see the above image.

Why ?

Magento 2 Have Any Port forwarding Restriction?,

Suggest Me How to Change My Configuration to works both machine(with css + images)?

How to get pub static content also from host machine while port forwarding?.

OR Magento 2 need php support for install in hostmachine, So, Remote Machine also need same php Support ?

  • Do you set the base_url? What Magento version are you using? (2.0, 2.1 etc). There were some bugs fixed in the area of caching host names when no base_url was defined (it would remember the first host name it saw). I would look at the HTML of the returned page to see what the URL to the CSS etc files are - are they coming back correct? Can you open the CSS file in a web browser and download them? – Alan Kent Sep 26 '16 at 18:08
  • @AlanKent Thanks for you response, I update my question. Please review Update 2 content – Rajkumar .E Sep 27 '16 at 5:35
1

I have missed my configuration setup, that is what this problem occur,

hostmachine ip: 192.168.1.5(hostmachine.com)

loadbalancer docker ip: 172.11.0.30(mymagentohost.com)

remote machine ip 192.168.1.14(remotemachine.com)

Before I added hostmachine ip addr to remote machine

# vim /etc/hosts

192.168.1.5 hostmachine.com

Then, Test Now,

Go to the browser type

192.168.1.5:3000

Throw Above Error and Not showing magento2 home page.

After I change Some Configuration in remote machine

host-machine hostname to docker load-balancer machine hostname assign to host-machine ip.

# vim /etc/hosts

192.168.1.5 mymagentohost.com

Now, Go to the browser type

192.168.1.5:3000

Check it Its worked for me, show Magento 2 site on my remote machine. Without CSS. and Images

But, still I don't know magento 2 have any port restriction or Not

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.