how to hide port when viewing page from page source (

Posted October 29, 2016 3.2k views

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.

My nginx conf :

server {

    listen 443;

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

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

    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_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;

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
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 "" /home/kyo/webroot

(Make sure you change 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
    and sometimes showing :

    **400 Bad Request The plain HTTP request was sent to HTTPS port nginx**