Reputation: 7804
I have php program which I run via CLI. The aim of program is to connect some address http and get some data. Its works OK. But I want to use other IP address of my webserver instead of primary. Is there any solution for this ?
EDIT Webserver has multiple ip address. I want to use any of them I choose at any request. If not possible at least 1 specific one. I have tried CURL_INTERFACE, and its not sending data while i give other ip than primary
HOSTNAME=server.xxxx.net
TERM=xterm
SHELL=/bin/bash
HISTSIZE=1000
SSH_CLIENT=<my ip> 23929 22
SSH_TTY=/dev/pts/1
USER=root
LS_COLORS=<blah blah>
MAIL=/var/spool/mail/root
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
PWD=/root
LANG=en_US.UTF-8
HISTCONTROL=ignoredups
HTTP_PROXY_REQUEST_FULLURI=0
SHLVL=1
HOME=/root
LOGNAME=root
CVS_RSH=ssh
SSH_CONNECTION=<my ip> 23929 <server ip> 22
LESSOPEN=|/usr/bin/lesspipe.sh %s
G_BROKEN_FILENAMES=1
_=/usr/bin/printenv
IPTable rules
xx.xx.xx.xx is servers primary ip address
*filter
:INPUT ACCEPT [85405:31617594]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [92024:84346360]
:acctboth - [0:0]
-A INPUT -j acctboth
-A OUTPUT -j acctboth
-A acctboth -s xx.xxx.xx.xx/32 ! -i lo -p tcp -m tcp --dport 80
-A acctboth -d xx.xxx.xx.xx/32 ! -i lo -p tcp -m tcp --sport 80
-A acctboth -s xx.xxx.xx.xx/32 ! -i lo -p tcp -m tcp --dport 25
-A acctboth -d xx.xxx.xx.xx/32 ! -i lo -p tcp -m tcp --sport 25
-A acctboth -s xx.xxx.xx.xx/32 ! -i lo -p tcp -m tcp --dport 110
-A acctboth -d xx.xxx.xx.xx/32 ! -i lo -p tcp -m tcp --sport 110
-A acctboth -s xx.xxx.xx.xx/32 ! -i lo -p icmp
-A acctboth -d xx.xxx.xx.xx/32 ! -i lo -p icmp
-A acctboth -s xx.xxx.xx.xx/32 ! -i lo -p tcp
-A acctboth -d xx.xxx.xx.xx/32 ! -i lo -p tcp
-A acctboth -s xx.xxx.xx.xx/32 ! -i lo -p udp
-A acctboth -d xx.xxx.xx.xx/32 ! -i lo -p udp
-A acctboth -s xx.xxx.xx.xx/32 ! -i lo
-A acctboth -d xx.xxx.xx.xx/32 ! -i lo
-A acctboth ! -i lo
COMMIT
Upvotes: 0
Views: 553
Reputation: 475
If you can use curl for outgoing http requests, you can set an option in curl: CURLOPT_INTERFACE
curl_setopt($curlh, CURLOPT_INTERFACE, "xxx.xxx.xxx.xxx");
**CURLOPT_INTERFACE**: The name of the outgoing network interface to use. This can be an interface name, an IP address or a host name.
PHP Manual: curl_setopt
Upvotes: 1
Reputation: 738
Depends on http server you are using , you can bind your "virtual host" configurations to specific address and port. in Apache2 for example :
<VirtualHost **127.0.0.10:8080**>
ServerAdmin myemail@mywebsite.com
ServerName mywebsite.com
ServerAlias www.mywebsite.com
DirectoryIndex index.php index.htm
DocumentRoot /var/websites/mywebsite.com/www
<Directory "/var/websites/mywebsite.com/www">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog logs/mywebsite.com-error_log
</VirtualHost>
With nginx , something like :
server
{
server_name example.com www.example.com;
**listen 66.113.100.140:80;**
access_log /var/log/ngnix/example.log;
error_log /var/log/nginx/example.error.log;
location /site {
alias /data/www/content/site/example;
}
location / {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_connect_timeout 10;
proxy_read_timeout 10;
proxy_pass http://10.15.20.10:8107/;
}
}
Also starting from PHP 5.4 there is build in web server that could be used for testing purposes. Generally you can bind to any local address as following :
$ cd ~/public_html
$ php -S 127.0.1.1:8000
Upvotes: 1