Question

How do I point my custom domain to my IP:Port using reverse proxy at nginx

  • Posted April 28, 2022
  • Nginx

I have a wordpress website pointed to my droplet ip (143.198.196.140) and i want to point it with port. I have been reading some tutorials at the community but i am still lost on how to set up the droplet ip:port using the reverse proxy.

The setting of my reverse proxy right now is :

server {
        listen 80 default_server;
        server_name _;
        return 301 https://$host$request_uri;
}

server {
        #listen 80 default_server;
        #listen [::]:80 default_server ipv6only-on;

        listen 443 ssl;
        listen [::]:443 ssl default_server;

        #ssl    on;
        ssl_certificate /etc/nginx/certificate.crt;
        ssl_certificate_key     /etc/nginx/private.key;

        root /var/www/html;
        index index.php index.html index.htm;

        # Make site accessible from http://localhost/
        server_name localhost;

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

        location / {

                proxy_pass https://langkahhoki.com;
                proxy_ssl_server_name on;
	 }

        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root /usr/share/nginx/html;
        }

        location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.0-fpm.sock;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #       deny all;
        #}
}
Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

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.

Thank you for the reply. I have tried to edit according to your guide, like this one

# Make site accessible from http://localhost/
        server_name localhost;

        #proxy_set_header       X-Real-IP       $remote_addr;
        #proxy_set_header       X-Forwarded-For $proxy_add_x_forwarded_for;

        location / {

                proxy_pass https://langkahhoki.com:9443;
                proxy_ssl_server_name on;
                proxy_set_header        X-Real-IP       $remote_addr;
                proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                # try_files $uri $uri/ =404;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules
        }

and when i open the langkahhoki.com:9443, it can not be open, it return with This site can’t be reachedlangkahhoki.com took too long to respond. Do i need to set up the port that i want to use first?

Thank you very much

Hi @mpojt2701,

You’ll need to edit the following part:

        # Make site accessible from http://localhost/
        server_name localhost;

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

        location / {

                proxy_pass https://langkahhoki.com;
                proxy_ssl_server_name on;
	 }

The proxy should look like:

        location / {

                proxy_pass https://IPADDRESS:PORT;
                proxy_ssl_server_name on;
                proxy_set_header        X-Real-IP       $remote_addr;
                proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
	 }

You’ll need to add your Domain or IPADDRESS and PORT on the proxy_pass directive.