简体   繁体   中英

Wamp - access project via IP instead of localhost

I try to make my project "public", so everyone in my LAN can access it. Currently I can only access my projects via http://localhost/project or by their virtual host name eg http://myVirtualHostName .

I need the projects to be accessible in my entire LAN, eg like this:

http://192.168.1.123/project or http://192.168.1.123/myVirtualHostName .

But If I try to access the projects from my own client or from another computer in my LAN, I get 403 Forbidden: You don't have permission to access /projectName/ on this server. .


EDIT : I was able to solve the first problem, I can now access links under C:\\wamp64\\www thanks to this answer , by changing the following block in C:\\wamp64\\bin\\apache\\apche2.4.33\\conf\\extra\\httpd-vhosts.conf

from

<VirtualHost *:80>
  ServerName localhost
  ServerAlias localhost
  DocumentRoot "${INSTALL_DIR}/www"
  <Directory "${INSTALL_DIR}/www/">
    Options +Indexes +Includes +FollowSymLinks +MultiViews
    AllowOverride All
  </Directory>
</VirtualHost>

to

<VirtualHost *:80>
  ServerName localhost
  ServerAlias localhost
  DocumentRoot "${INSTALL_DIR}/www"
  <Directory "${INSTALL_DIR}/www/">
    Options +Indexes +Includes +FollowSymLinks +MultiViews
    AllowOverride All
    Require all granted
  </Directory>
</VirtualHost>

...and by restarting apache after it.

Now I can access a project in C:\\wamp64\\www like this http:\\\\192.168.1.123\\myProjekt . But I still don't know how to access a virtual host by using my servers ip address.

If I try http://192.168.1.123/myVhostName then I get Not Found The requested URL /myVhostName was not found on this server. , even though Require all granted is set for each virtual host .

I also restarted the DNS-Server.


How can I solve this?

I am using WAMP 3.1.3.

Ok, first as you dont seem to understand what a Virtual Host is and what it is used for I'll start with a little explanation.

Virtual Host are a way of getting one Apache to serve multiple site as if you had multiple Apache's. When correctly configured, Apache looks at the domain name of the incoming connection and tries to match it to a VH definition. If it can it serves the site from the DocumentRoot defined in that VH.

If it cannot match the domain name it serves the first VH in the definition file. Thats another reason why you make the first definition that of localhost and always set the access to Require local , which will tell the client You dont have access if they just use your WAMPSevrer's IP address and not a valid domain name.

As of WAMPServer V3 even localhost is defined as a Virtual Host.

So first leave the localhost VH defines as it was, like this, but with Require local as you never want to allow remote access to the WAMPServer homepage with the tools on it, as it wont run properly from a remote client because most of the tools assume localhost which when run from a client wont exist as it is always assumed to be on this PC ie the client.

<VirtualHost *:80>
  ServerName localhost
  ServerAlias localhost
  DocumentRoot "${INSTALL_DIR}/www"
  <Directory "${INSTALL_DIR}/www/">
    Options +Indexes +Includes +FollowSymLinks +MultiViews
    AllowOverride All
    Require local
  </Directory>
</VirtualHost>

Now define your real site as another VH. I will assume its going to be called example.local but change this everywhere to whatever you want the site to really be called.

<VirtualHost *:80>
    ServerName example.local
    ServerAlias www.example.local
    DocumentRoot "${INSTALL_DIR}/www/example"
    <Directory "${INSTALL_DIR}/www/example/">
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

NOTE: The DocumentRoot folder does not even have to be in the ${INSTALL_DIR}/www/ it could be anywhere on that disk or even on another drive completely.

Now you also say you have a on site DNS Server. So get the admin to define example.local and point it to the IP Address of the PC running WAMPServer. This should make it easily accessible from any PC that uses that DNS Server by using the domain name example.local or www.example.local

If you want a bit more security you might also like to make the Require more specific, so if the site is only going to be run on one subnet amend the Require all granted to be

Require ip 10.30.20

Note, I only used the first 3 quartiles of the IPV4 address, which will grant access to any client IP in that segment.

Any question, just leave a comment and I will get back to you.

I just changed line:DocumentRoot from:

c:/wamp64/www 

to:

c:/wamp64/www/myproject 

and it works for me!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM