My Windows 10 pc has xampp installed. I use it for multiple projects so my folder structure is similar to:
xampp
|-htdocs #dummy localhost
|-htdocs-projecta
|-htdocs-projectb
|-etc
I have set up my http-vhosts.conf file and hosts file so that when I go to projecta.dev or projectb.dev then apache returns the correct website.
I have set up my pc to act as a wifi hotspot and connected my iphone to the hotspot. I have configured the wifi connection on my iphone so that my pc acts as a proxy. This means when I go to projecta.dev on my phone I can see the website from my computer.
This is where I am having problems - using this method it appears I can ONLY see websites that are on my computer (ie I am unable to download resources from other websites - such as jQuery or Analytics).
How can I set up my PC and iPhone so I can access the local project domains on my pc from my iphone, as well as having regular internet access to download other scripts?
[edit]
More info:
My vhosts file is configured like this:
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs\"
ServerName localhost
<Directory C:\xampp\htdocs>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs-projecta\public_html"
ServerName projecta.dev
<Directory C:\xampp\htdocs-projecta>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs-projectb"
ServerName projectb.dev
<Directory C:\xampp\htdocs-projectb>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
...
And my hosts file is:
127.0.0.1 projecta.dev
127.0.0.1 projectb.dev
...
When I access project-a.dev from my phone, it loads the website excluding third-party resources (such as Google Fonts and jQuery). When I go to Google it loads my localhost, with other pages / folders returning a 404. This led me to think the issue is with the vhosts configuration - it can't find a matching server name and is loading the default localhost.
So I changed <VirtualHost *:80> to <VirtualHost projecta.dev:80> but that had no effect. I also added Listen projecta.dev:80 but that also had effect.
How do I set up vhosts to ignore all requests that but those in the vhosts file / with ServerNames?
First, you may check whether your iPhone able to connect to any website or not after you connect to the wifi hotspot, e.g. www.google.com
If yes and you still unable to connect, you may check whether the link of the jquery script is correct or not by try on your laptop. If there having the same problem with your phone, then you inspect element and check whether the script successful download or not. Sometimes, we may put the jquery link wrongly.
If all are ok but the iPhone still cannot download it, I think you may download those jquery script and put into the htdoc folder together with your project. Actually this way can save a lots of time.
Hope this can help you!
I had set up my iphone to have a proxy connection to my pc for ALL requests.
What I had to do was create a .pac file on my pc so, on a per-request basis, it would tell my iphone whether to access my pc as a proxy or connect directly to the resource.
Here is my proxyfile.pac:
function FindProxyForURL(url, host)
{
//localhost projects
if (dnsDomainIs(host, "projecta.dev")) return "PROXY 192.168.1.87:81";
if (dnsDomainIs(host, "projectb.dev")) return "PROXY 192.168.1.87:82";
//... etc
//everything else
return "DIRECT";
}
As you can see, I am now telling my iphone to use my computer to proxy specific urls to different ports on the same ip. If I set it to port 80, then they would all access my default localhost instead of the website they are supposed to load. This meant I had update my vhosts file as well:
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs-projecta\public_html"
ServerName projecta.dev
<Directory C:\xampp\htdocs-projecta>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Listen 81
<VirtualHost *:81>
DocumentRoot "C:\xampp\htdocs-projecta\public_html"
ServerName projecta.dev
<Directory C:\xampp\htdocs-projecta>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
For each project, I copy/paste the VirtualHost block, change the port and add a Listen command.
With this set up I am now able to access, on my pc and iphone http://projecta.dev, as well as the internet in general (e.g. http://google.com) so that I can download external resources as needed (such as jQuery, google fonts and so on).
Related
I recently installed XAMPP and got the installation spot-on after a few attempts. I've followed instructions to download a copy of my website (from public_html) and database and got the files under htdoc and set up and imported the database; all well and good.
However, I've been battling a bit with setting up the local virtual host environment, and it is here I think I may have inadvertently screwed something up - Whenever I call my site at localhost/shf21.build, I get the very same; there appears to be a second instance of http// (incorrect, as there is no colon between the p and the first /) somehow infused 'just after the initial https:// (yes, I created an SSL cert/key pair for this site), as follows:
https://**http//**localhost/shf21.build/wp-signup.php?new=localhost
And it is the same on all 4 browsers (Chrome, FireFox, Opera and Edge), enven after clearing browser data and cookies several times.
Other changes I made was in C:\xampp\apache\conf\extra\httpd-vhost.conf and C:\Windows\System32\drivers\etc\hosts as follows:
httpd-vhost.conf
<VirtualHost shf21.build:443>
ServerName shf21.build
DocumentRoot "C:/xampp/htdocs/shf21.build/"
SSLEngine on
SSLCertificateFile "certs/shf21.build/server.crt"
SSLCertificateKeyFile "certs/shf21.build/server.key"
</VirtualHost>
Hosts
127.0.0.1 https:/localhost/shf21.build
I have flushed DNS and reset network settings a few times, to no avail. I do hope there is someone that will be able to assist me in sorting out my dilemma...
Regards Gerhard
I have a version of keycloak running on my AlmaLinux server. This service runs on port 8080. I can access it using <SERVER-IP>:8080. I however, want to access the service using mysubdomain.mymaindomain.com. This way, the user is not confronted with port-numbers, and I suppose using autoSSL is easier (I cannot get it to work on a different port).
I tried multiple things.
The first (I know, very sketchy) was rerouting using htaccess. I made a rewrite condition that looped to localhost:8080. At first glance this worked, but redirects did not work. I suppose this is, since the service thinks it runs on 'localhost:8080' (what it of course does), and thus redirects (on the browser side) to localhost:8080/home for example.
The second thing I tried was adding this code to the virtualhost config file.
I added this using the WHM environment in the server configuration > apache configuration > include editor. There I tried both 'Pre Virtual Host Include' and 'Post Virtual Host Include' (Originating from here).
<VirtualHost *:80>
DocumentRoot "/public_html/keycloak_public"
ServerName mysubdomain.mymaindomain.com
# Other directives here
</VirtualHost>
That did not work, I found out I had to use a proxy. So I appended the following code behind the former part. (Originating from here).
<VirtualHost *:80>
ServerAdmin me#mymaindomain.com
ServerName mysubdomain.mymaindomain.com
ProxyPreserveHost On
# setup the proxy
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>
However, when I go to mysubdomain.mymaindomain.com this still loads the empty directory, instead of the equivalent of :8080.
According to the above mentioned thread, I have to enable proxy somehow, but I did not find a way to do so in Cpanel, so I kind of assumed it was enabled (I'm sorry). Can that be the problem, or should I look somewhere else in order to fix this problem?
The solution turned out to be replacing the * with the server-ip!
I have a server with multiple services and tools with web based user interface (rundeck, jenkins, sonarqube,...) and I want the devteam can access with a properly url, not the server IP and a port.
IE:
- companyName-rundeck.com
- companyName-jenkins.com
- companyName-sonarqube.com
What would be the best approach to do that?
What is most often use for this purpose is some kind of reverse proxy. I will describe the simple Apache setup, but it should be as easy to configure it using nginx or HAProxy.
For example purposes, let's sat that you have 3 services running on the server:
Jenkins on port 8080
SonarQube on port 9000
RunDeck on port 4440
First, in order to distinguish between services just by using domain name, you will need to create several entries in your DNS, pointing the names to the server IP address:
jenkins.example.com A 192.0.2.2
sonar.example.com A 192.0.2.2
rundeck.example.com A 192.0.2.2
Next, (if you have not already done that) install Apache HTTP server:
yum install httpd
Create a file /etc/httpd/conf.d/proxy.conf:
<VirtualHost *:80>
ServerName jenkins.example.com
ProxyPreserveHost On
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>
<VirtualHost *:80>
ServerName sonar.example.com
ProxyPreserveHost On
ProxyPass / http://localhost:9000/
ProxyPassReverse / http://localhost:9000/
</VirtualHost>
<VirtualHost *:80>
ServerName rundeck.example.com
ProxyPreserveHost On
ProxyPass / http://localhost:4440/
ProxyPassReverse / http://localhost:4440/
</VirtualHost>
(the logic should be quite clear, for detailed explanation, look at the docs)
After that, just start the httpd service: service httpd start.
The instructions are for CentOS, but should not differ too much for other distros
In case it does not work as expected (without any obvious trace in logs) try with disabled selinux (setenforce 0 && service httpd restart)
I'm trying to create a subdomain in my virtual server (it's a centOS). I have edited the httpd.conf file like this:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /var/www/html/zend/
<Directory "/var/www/html/zend">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ServerName zend.mydomain.es
</VirtualHost>
When I try www.mydomain.es it's work fine, but when I try zend.mydomain.es I get Server Not Found error.
Are there any other files i must configure for this to work?
You should also setup dns for the your subdomain and make sure subdomain is pointing to the correct ip
Also check ping if it is replying:
ping zend.mydomain.es
If the IP is correct check both Apache logs (error.log and access.log).
I would recommend verifying your DNS settings for the subdomain.
E.g. If you are hosting with GoDaddy, I would recommend making sure
you have an entry for your subdomain there and that the IP points to
the same box.
Next, if you haven't yet, after you make your changes to httpd.conf
you need to restart the httpd service for the changes to take
affect. So try service httpd restart
Hopefully one of those helps solve your issue.
I have a website I am building on localhost:
http://localhost/my-website
I need to test it on my iPhone, but I'm not sure how to go about it. Do I just change my httpd-vhosts.conf file, and, if so, what are the settings?
Assuming that your development machine is called my-macbook-pro, you should just be able to navigate to http://my-macbook-pro.local/mywebsite on your iPhone.
To expand slightly on Richard J. Ross III's answer, "localhost" is a name used to refer only to the local computer. In order for your iPhone to be able to access content on that machine it must:
Have an IP address on the same network as the server machine.
This can be achieved by connecting the iPhone to a wireless access point that is on the same network as the PC, or by creating an ad-hoc wireless network between the two devices.
Respond to HTTP requests from network clients.
Assuming the server and the iPhone are on the same network, it should be possible for traffic to flow between them. However in order for your web content to be visible to the iPhone, the web server must also be configured to respond to requests made to the server machine's IP address.
This is not normally a problem as web servers are commonly configured to respond to HTTP requests sent to any of the machines IP addresses. It is possible that a server could be configured to only respond to local requests, however this is not a typical default setting
How you check or modify this setting is dependent upon the HTTP server software you are using. As this information is not specified I will include instructions for Apache2 as this is a very common choice of HTTP server.
Apache's Listen Directive
Apache's main configuration file is httpd.conf and it is located in the conf subdirectory of your Apache directory. The location of your Apache root directory will vary depending upon what operating system you are using and whether or not a custom location was chosen at installation.
The httpd.conf file contains a directive named Listen which controls the interface (IP address and port) on which Apache listens for incomming HTTP requests.
The default form of this directive is commonly
Listen 80
This specifies that the machine will respond on any of it's IP addresses to requests made on port 80, which is the default port for HTTP traffic.
You can modify the Listen directive to use any address associated with the machine including the loopback address (127.0.0.1) which the name localhost resolves to.
If Apache is set up to only listen on the loopback address then your server machine will only respond to requests made on the local machine. In this configuration, your Listen directive will look something like:
Listen 127.0.0.1:80
If this is the case, you will need to change to either listening on all addresses, as in the example above, or listening only on the address used by the iPhone to communicate with the server machine.
100% working solutions
(for linux + apache + vhosts)
If you are using vhost (several sites on the same server apache) the next several tips can help you view your local websites on mobile:
1) VHOST edit -You should go to /etc/apache2/sites-available/ on your server. There can be several files .conf, each file contain a virtual host configuration for apache. Default file will look like 000-default.conf. Open it (or another one) with admin permissions sudo. In that file you should see something like this:
<VirtualHost *:80>
ServerName auction.dev
ServerAdmin test#test.com
DocumentRoot /var/www/public_html/html
ErrorLog /var/www/logs/error.log
CustomLog /var/www/logs/access.log combined
</VirtualHost>
2) XIP.IO - this special service (its totally free) can help you. You should add to .conf file next line - ServerAlias auction.dev.*.xip.io, after this operation your file will look like this:
<VirtualHost *:80>
ServerName auction.dev
ServerAlias auction.dev.*.xip.io
ServerAdmin test#test.com
DocumentRoot /var/www/public_html/html
ErrorLog /var/www/logs/error.log
CustomLog /var/www/logs/access.log combined
</VirtualHost>
After editing you should save this file and restart apache with command sudo apachectl restart.
3) View from mobile - You need to know ip of your server, in my situation ip = 192.168.1.247. Now in your mobile browser just type auction.dev.192.168.1.247.xip.io and you should see your local website.
I'm working with xampp. localhost works on port 8080.
I just find my ip with ipconfig and surf to http://10.0.0.1:8080.
That easy!
If you just want a better feel of the native behavior instead of just browser dev tools you can use the iOS simulator and type localhost:xxxx in safari app.
For OSX, go to System Preferences / Sharing. There, you can find and change the name of your computer. In the same section, you also have to enable "Internet Sharing" service with "iPhone USB" port.
Then you can view your website at http://{ computer_name }.local/my-website.
When you connect your ipod with the cable to your macbook the device appears in safari on your mac in the menu under developers. When you click this option you can see exact the same as you can on your ipod.
Following these steps worked for me:
https://mtm.dev/iphone-localhost-mac
It is based on Internet Sharing via USB and setting & using the device_name which is then used as mentioned as <device_name>.local:<port>