Port Redirect on Mac - php

What is the easiest option to redirect a request to a different host/port?
Here is my entire scenario:
I am making a request using php to a certain ip and port. The response includes another url location, but it is badly configured and instead of including ip and port, it simply includes a server name. Now, if I access the entire url location that I have as response with the server name replaced with the proper ip and port it works.
I've tried editing /etc/hosts setting the server name to the ip address, but how do I workaround the port too?
I am using mac osx 10.9.4, and I've tried some things with ipfw and pf, but neither really worked.
Thanks.

I had a similar problem quite recently on Mavericks (10.9). The way I solved it included 2 steps:
hosts file
Simply added a line similar to this:
127.0.0.1 www.someaddress.com
port forwarding
To set up port forwarding I used ipfw, which worked fine, e.g:
ipfw add 100 fwd 127.0.0.1,9001 tcp from any to any 80 in
In the example above port 9001 is forwarded to port 80. Even though ipfw is deprecated it still works.

Related

Yii2: Add local nginx proxy to request trusted hosts

I have nginx and php7.2-fpm installed on single Debian machine. nginx forwards requests to php through linux socks. I use yii2 which has request->trustedHosts setting. I need to add my local nginx there to be able to get x-forward-proto and other secure headers set.
Which address do I need to set up in trustedHosts? Ipv4 and Ipv6 cidr loopbacks do not help.
I just don't understand what network interface nginx uses to proxy request - loopback (127.0.0.1), some internal ip, external (internet) ip? So what is the default outbound ip nginx select to bind (should I use proxy_bind to change it to 127.0.0.1)?
Thanks in advance.
request->trustedHosts setting is checked against ip address provided by $_SERVER["REMOTE_ADDR"]. So check the contents of this variable.
If your machine is behind a proxy, $_SERVER["REMOTE_ADDR"] should contain proxy's ip. Try adding that ip into trustedHosts array.
(if there is no proxy and your machine is directly connected to the internet, it seems that it makes no sense to use trustedHosts. In that case $_SERVER["REMOTE_ADDR"] would contain client's ip, but you should NOT trust any client by adding "0.0.0.0/0" into trustedHosts)

WAMP my own internal ip doesn't work on browser

I have installed WAMP and my computer ip is http://192.168.1.142/
When I entered it in browser I got nothing, my WAMP server doesn't see this ip
I got error :
**This 192.168.1.142 page can’t be found
No webpage was found for the web address:
192.168.1.142 HTTP ERROR 404**
http://prntscr.com/fx1mri
Tried configure httpd.conf Want add there row Listen 192.168.1.142:80 and when I run restart WAMP it's not green , means apache doesn't run ,
How correct this ? Why my local IP can't reach in my browser ?
Probably there will be 2 approach to solve this-
You need to provide the ip-address instead of localhost in your code.
Try not to use Skype at the same time since it uses same port number.
If it's your local computer I'll recommend you to use "http://localhost" or "http://127.0.0.1". Prefer localhost.
If you want to use some other cool hostname you should add it to your (windows)hostfile %SYSTEMROOT%\System32\drivers\etc\hosts
Example of input:
127.0.0.1 localsecure
Other programs like skype and torrent are usually using the same ports. Go to your httpd.conf and change listen to for example 82 and the servername to localhost:82(the port is always the same as the value of listen). And than you can use localhost everywhere for example your phpmyadmin would be:
localhost:82/phpmyadmin
And the directories:
localhost:82/..
Credit: ndsmyter

How to remove port number from url using apache server?

I have installed Apache, PHP, Mysql in ubuntu system.
I have changed the port of apache server 80 to 802 in httpd.conf file.
I am accessing localhost from the below URL successfully.
http://localhost:802/
But the thing I want to access the localhost without using port number in the URL. Where I need to change for this.
Please suggest.
Where I need to change for this.
In httpd.conf where you set the port number to 802, set it back to 80.
HTTP operates on port 80 by default, and web browsers use that default by convention. Since you have changed that default, you need to specify the port in the address. Otherwise the web browser will attempt to connect to port 80 and won't find your server.

Running PHP server without port

I have a typo3 folder in /var/www/my_folder, I want to run php server inside my_folder,
I run php -S localhost:8080 but I have problems later with URLs, I want get rid of :8000.
when I try php -S localhost I get
Invalid address: localhost
How can I manage this ?
You can run the PHP web server on on port 80, which is the default for HTTP, like this:
php -S localhost:80
Then you can visit http://localhost in your web browser.
However, it's common practice to use a different port for local development so that you don't have any conflicts between your dev environment and anything else which may be running on your machine. If you're sure you're not using port 80 anywhere else, feel free to use it.
What you can't do is omit the port number like you have in your second example.
Without explicite port usage, browsers use port 80 for HTTP and 443 for HTTPS. So if you want your URLs you use 'later' to not include the port, start the PHP interpreter with the one you need the URLs for.

Weird PHP not displaying over local ip address

I have the following setup below:
Amazon EC2 instance.
IPs:
192.168.1.200 = eth0 = x.x.x.x public ip address
192.168.2.200 = eth1
Apps:
Apache
vhosts:
-domain.tld
PHP
The strange part is this. When I try to browse domain.tld over public ip address, its working fine. But when I browse it through 192.168.2.200, it will keep waiting until no display coming out in the browser. A simple index.php with a text "test" inside is working fine. Only when the php codes like phpinfo() will not be working.
Do you have any idea what could be the problem in php or apache or my network? I have already open all ports on the firewall but the problem still persist.
Thanks.
I found the issue - it's due to incorrect network routing table on the EC2 server including blocking of traffic that rectified through playing security settings.
Thanks to your comment #Dagon.

Categories