Config Nginx for getting Port in URL or Header - nginx

I have an Ubuntu virtual server where many application servers are running on different ports, I want all its inputs to be on the same domain and port. How can I configure Nginx to receive the port in the URL or header and transfer requests with all of its headers to the local port?
Example of port in URL:
domain.com/1256 -> 127.0.0.1:1256
domain.com/1256/abcd -> 127.0.0.1:1256/abcd

Related

Nginx proxy reverse out port

I want to define out port of my nginx server.
Actually some thing like port forwatding by iptables in nginx.
Request:
Client via(ip:port) send to nginx(ip:80).
Nginx via( nginx ip:client port) send to server B(ip:80).
Response:
Server B via(ip:80) send to nginx(ip:client port).
Nginx via(ip:80)send to client(Ip:port)
I have a server running nginx on it listen to port 80.
It recives requests from client and acording to location in request, forwards it to diferent proxy servers.
Problem:
I need to nginx connects to my proxy server by port which client conects to it.
For example:
Client connects to port 80 of my nginx server via port 1000 and now I want to my nginx connects to lisetenig port of my other server via port 1000.
Forwarded Ip is no matter.
And connection protocol is tcp http.

Magento2 website with nginx(with SSL termination) and varnish cache

I have hosted magento2 website with Nginx, SSL termination, and varnish cache. Varnish cache is running on port 8080 and the Magento2 website is hosted on Nginx port 8081. Http and Https traffic is accepted by the same Nginx and forwarded to the varnish cache(SSL terminated).
NGINX Varnish Magento2 all are running in the same server
I have two questions,
If I tried to access the magento2 website which is running on port 8081, directly from the internet, it bypasses the SSL termination and directly connects to the website. How can I restrict that?
When configuring magento2 baseurl, If I want to host it on a different port rather than the default 80 port, Do I need to give the port number at the baseurl configuring step? eg:- php bin/magento setup:install --base-url=http://www.example.com:8081
Assuming you want to block the port from the public internet, you have multiple options. Assuming you have SSH access, you can block the port with iptables:
/sbin/iptables -A INPUT -p tcp --destination-port 8081 -j DROP
/sbin/service iptables save
Assuming you're using a non-standard HTTP port (not 80 or 443), yes, you would need to specify that in the configuration.
nginx shouldn't be listening on 8081 to the outside world to begin with. You probably need something like
server_name localhost;
in your nginx configuration

Http port 80 is not open but Port 8080 is opened and website not opening

I have redhat linux server GNU. The port 80 is not open there, and port 8080 is opened. Now i am trying to open a website. How to know which port apache using and if port 80 is not open can http://xxxx (website URL) work? As of now for me the website is not opening.And when i am typing this in the browser http://xxx the page is not loading and url showing is https://xxx
As I understand you want to know which port apache is using to deliver web content. You can use below commands to check the ports.
For a general check if an app is running you could just use
“ps aux | grep apache2” Or "ps aux | grep httpd" for redhat/centos.
lsof -i list open ports and the corresponding applications.
By default, HTTP uses port 80 and HTTPS uses port 443, but you can use a URL followed by opened port like http://www.example.com:8080/path/ which specifies that the web browser connects instead to port 8080 of the HTTP server.
If you have a secure socket layer certificate (SSL) on your website, you can automatically redirect visitors to the secured (HTTPS) version of your site for a secure connection.

I'm running a WAMP server. But can't forward ip through router

I want to forward the ip of my localhost server for being publicly accessible.
But while trying to configure my router on port 80(as it is localhost's listening port) it shows "Error: The port of the remote web management is conflicting with of the virtual server."
Is there any fix to it?
I was able to resolve this by updating the Web Management Port to a port other than 80. This setting for me was found under Security -> Remote Management -> Web Management Port.
After updating, I could enable port forwarding on port 80.

Elastic Beanstalk EC2 instance responses http request on both port 5000 and port 80

I setup an Elastic Beanstalk with load balancer forwarding port 80 to port 5000 on EC2 instance. My EC2 instance listens on port 5000, not port 80. The EC2 instance has a private ip 172.31.14.151. On another EC2 which is in the same subnet as the EC2 running the Springboot web server, I got http responses for the two following http request:
curl 172.31.14.151:5000
curl 172.31.14.151:80
I do not understand why I got http response from 172.31.14.15:80. The EC2 I am running the curl command is on the same subnet as the EC2 running webserver. The http request should not go through any router and not through load balancer. But the webserver is running on port 5000, not port 80.
Is there a Nginx instance running on the EC2 instance with webserver?
If I configure the webserver to listen on port 80 and let the Elastic loadbalancer forward port 80 to port 80 on EC2 instance, I got Nginx 502 bad gateway response from doing the curl request
curl 172.31.14.151:80
I don't know which Elastic Beanstalk Solution Stack you are using, but most of the AWS Solution Stacks come coupled with Proxy Servers by default. For example, if you're running Java SE the proxy server is NGINX, but if you're running Java with Tomcat the proxy server is Apache.
By default these proxies accept HTTP Traffic on the default HTTP port (80), manage the connections, then proxy the requests from the backing application server (In your case, port 5000). This helps manage the connection to the backing application, as well as serve static content, or if you configure them correctly, customized Error messages based on the HTTP Status code. I'd suggest that if you can, you send the load balancer traffic to port 80 because Apache or NGINX can usually handle connection load better than most custom applications.
Have you check inbound rules on the security group that you've use ?
Is there a Nginx instance running on the EC2 instance with webserver? - Yes is it. When you create new environment, you can choose pre-configured platform, and choose NodeJS Platform.
If your application is heterogeneous applications, is better to use container. You can deploy your containerized applications on Elasticbeanstalk or use Elastic Container Service instead.

Resources