Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx remove port number :8080 in the url

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?

like image 229
ServerSideSkittles Avatar asked Oct 29 '25 17:10

ServerSideSkittles


1 Answers

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.

like image 112
oznu Avatar answered Oct 31 '25 07:10

oznu