Nginx remove port number :8080 in the url

ServerSideSkittles

I am using apache and nginx on a ubuntu VPS. Apache has priority of port 80 as I host websites there.

I have a small nodejs app that runs on port 3000. In the dir for the weblink i have a .htaccess file that redirects to port 8080 (reverse proxy on nginx) but I still can't get rid of the :8080 on the end.

Here is my .htaccess file

Options +FollowSymLinks
RewriteEngine on 
RewriteRule ^(.*)$ http://example.org:8080/$1 [R=301,L]

Here is my nginx config

server {
  listen 8080;
  server_name example.org;
  port_in_redirect off;
  root /var/www/example.org/webapp;
  access_log /var/www/example.org/log/access.log;
  error_log /var/www/example.org/error.log;

  location / {
    proxy_pass http://example.org:3000;
    proxy_redirect http://example.org:8080/ http://example.org/;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
  }
}

I have tried with/without port_in_redirect off; proxy_redirect http://example.org:8080/ http://example.org/;

and when I goto example.org it redirects to example.org:8080. Is there a way to have apache and nginx coexist without losing my apache sites on port 80?

oznu

You can use Apache as reverse proxy, you can direct it straight to the nodejs application, unless you had some reason for passing it through nginx as well. This will allow you to run multiple sites / applications on port 80.

Example .htaccess / httpd.conf:

RewriteEngine On
RewriteRule ^$ http://127.0.0.1:3000/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://127.0.0.1:3000/$1 [P,L]

The [P] tells Apache to proxy the request.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to remove port number 8080 from my domain name using nginx v1.14.1?

Remove port number in image url?

How to remove port 8080 in xampp?

Remove port number from a url in java

forward the domain and remove the port number from the URL

Hide port number in URL exposed by NGINX Docker container

Invalid URI: Invalid port specified in C# on specifying URL with port number in it like http://localhost:8080/jasperserver/rest

Nginx forward from domain A port 8080 to domain B port 80

How to get rid of port 8080 in URL?

How can remove the port number from live vue site url?

How to remove the :port number from the end of an IIS URL?

Nginx requires port 433 on URL

Why mysql is not working after port number of wamp is changed to 8080

How to recognize hostname on the port number 8080 in Ubuntu machine?

Failed to connect to port 8080: Connection refused Error number: 7 (cURL)

How do you remove the port number :8000 from project-open url links?

Redirect to a port number depending on the URL

Error with URL Redirection in codeigniter , I am using port 8080 "Apache/2.4.7 (Ubuntu) Server at sandbox.dev Port 8080"

nginx keep port number when 301 redirecting

NGINX: remove part of url permanantly

TNSLSR on port 8080

Port 8080 is already in use

Sending Udp on port 8080?

Gitlab on port 8080

Using LiveServer on port 8080

open port 8080 for listening

PHP error on port 8080

Redirect traffic to a domain with a port number without showing the port number in the URL

NGINX: Rewrite url and reverse proxy to a different port