how to hide port when viewing page from page source ( https://mydomain.com:443)

October 29, 2016 112 views
Nginx Ubuntu

Hello,
can anyone help me to hide the port and showing domain only when viewing site from page source ? port only visible if you see it from the page source.
screenshot:
http://image.prntscr.com/image/59e47f990fa547af9709e9f2a1272834.png

My nginx conf :

code
server {

    listen 443;
    server_name domain.me www.domain.me;

    root /home/kyo/webroot;
    index index.php;

    # SSL
    ssl on;
    ssl_certificate /etc/ssl/cert_chain.crt;
    ssl_certificate_key /etc/ssl/private/domain.me.key;

    ssl_session_timeout 5m;
        ssl_session_cache shared:SSL:50m;

    port_in_redirect off;

    # intermediate configuration.
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';

        # Diffie-Hellman parameter for DHE ciphersuites, recommended 2048 bits
        ssl_dhparam /etc/ssl/certs/dhparam.pem;

    location / {
     rewrite /sitemap.xml$ /sitemap.php last;
     rewrite /feed$ /rss.php last;
     rewrite ^/go/(.*)$ /go.php?id=$1 last;
     rewrite ^/view/(.*)$ /page.php?id=$1 last;
    if (!-d $request_filename){
     set $rule_4 1$rule_4;
    }
    if (!-f $request_filename){
     set $rule_4 2$rule_4;
    }
    if ($rule_4 = "21"){
     rewrite ^/mp3/(.*)(\/|\.)(.*)$ /search.php?q=$1&slug=$2 last;
    }
    if (!-d $request_filename){
     set $rule_5 1$rule_5;
    }
    if (!-f $request_filename){
     set $rule_5 2$rule_5;
    }
    if ($rule_5 = "21"){
     rewrite ^/(.*)$ /download.php?po=$1 last;
    }
}

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
    #Expire Header
    location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
        expires 1d;
        add_header Pragma public;
        add_header Cache-Control "public";
}

    #error_page 404 /404.html;

    # redirect server error pages to the static page /50x.html
    #
    #error_page 500 502 503 504 /50x.html;
    #location = /50x.html {
    #   root /usr/share/nginx/html;
    #}

    # y access to .htaccess files, if Apache's document root
    # concurs with nginx's one

    location ~ /\.ht {
        deny all;
    }
}

1 Answer

Are you sure it isn't written in source code like that?

As you said, it's working flawless when used from browser, you can only see it in source code.

Depending on solution, you probably need to remove it manually.
But care, if you use some CMS solution, make sure you didn't write somewhere URL with that :443.
For example, if you use WordPress, make sure you didn't type WordPress and Site URL with :443 at the end. This setting can be found under Settings, General.

If this is not the case, check manually.
SSH to your server and execute this:

  • grep -rn "https://mydomain.me:443" /home/kyo/webroot

(Make sure you change mydomain.me with your real one :) )
If there is files with :443 domain, it should show you which ones have that.
Go one by one, remove it from URL and you should be good to go.

This is not a big problem, :443 is anyways default, so everyone already knows that. :)

  • I've asked the owner of the script, he say that problem on my server not on hes script :/

    there's no files with :443
    grep: /home/kyo/webroot: No such file or directory

    edit: execute on wrong droplet :xd
    after execute command from you, is not showing anything.

    Ya that default port,but the problem is my sitemap also generate url with :domain.me:443/keyword-keyword
    and sometimes showing :

    **400 Bad Request The plain HTTP request was sent to HTTPS port nginx**
    
    • oh ya forgot to mention, I install the same script on different droplets and it's not showing domain.me:port :/
      but, im not using ssl on there.

    • the script owner just contact me again, he forgot to tell that I need to replace 80 to 443 port in function.php on old script.

      Thanks you for trying to help me :D/

Have another answer? Share your knowledge.