mending3
mending3

Reputation: 712

NGINX: Reverse proxy from location to port

on /etc/nginx/sites-available/x.x.x.x.conf, I have this entry:

   location /myapp {
       alias /var/www/html/myapp/public;
       index index.php;
       try_files $uri $uri/ @myapp;
 
       location ~* \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $request_filename$fastcgi_script_name;
                fastcgi_read_timeout 7200;
       }
 
   }
 
   location @myapp {
             rewrite /myapp/(.*)$ /myapp/index.php?/$1 last;
   }

currently I visit my website to x.x.x.x/myapp

How do I proxy it to x.x.x.x:8059?

Upvotes: 1

Views: 979

Answers (1)

qräbnö
qräbnö

Reputation: 3031

I am not sure if I understand your problem. Why don't ppl post their server blocks? I try anyway:

    location /myapp/
    {
        proxy_pass http://x.x.x.x:8059/;
    }

Or the other way round:

server
{
    listen 8059;
    server_name x.x.x.x example.org www.example.org;

    # …

    location /
    {
        proxy_pass http://x.x.x.x:80/myapp/;
    }
}

It can easily happen that now your paths are broken. Change them in code or check out proxy_redirect and sub(s)_filter for on-the-fly changes.

Browser -> Key [F12] -> Console and/or Network is always helpful.

Also nice on Windows: Install Git, open Git Bash and do a curl -IL <URL>.

Upvotes: 1

Related Questions