局域網訪問本地項目


phpstudy 開發環境中

1:在 D:\phpstudy\PHPTutorial\Apache\conf (你的安裝目錄) 下的httpd.conf文件中 添加監聽端口

    Listen 0.0.0.0:99

2.設置目錄的訪問權限 (httpd.conf文件)

    <Directory D:/phpstudy/PHPTutorial/WWW/chuanqi/public/>

      AllowOverride All

      Require all granted
    </Directory>

3.添加虛擬目錄(D:\phpstudy\PHPTutorial\Apache\conf)下的vhosts.conf文件中

    

<VirtualHost *:99>

#你的項目地址
DocumentRoot "D:\phpstudy\PHPTutorial\WWW\chuanqi\public"
ServerName 192.168.1.17
ServerAlias tp.cn

#你的項目地址
<Directory "D:\phpstudy\PHPTutorial\WWW\chuanqi\public">
Options FollowSymLinks ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>

4.在host文件中添加

127.0.0.1 192.168.1.17

這樣在同一個局域網中就可以隨便訪問你本地的項目了.

 

此時,訪問你本地的項目就牽扯到了跨域的問題

解決跨域問題

1.允許任何域名訪問 

header('Access-Control-Allow-Origin:*');

2.指定域名訪問
header('Access-Control-Allow-Origin:http://client.runoob.com');

3.允許多個域名訪問
$origin = isset($_SERVER['HTTP_ORIGIN'])? $_SERVER['HTTP_ORIGIN'] : ''; $allow_origin = array( 'http://client1.runoob.com', 'http://client2.runoob.com' ); if(in_array($origin, $allow_origin)){ header('Access-Control-Allow-Origin:'.$origin); }
至此,在同一個局域網就可以訪問你本地的項目了。
訪問的域名是:
192.168.1.17(你本地的IP地址)/admin/public/index.php/index/Index/login

 
 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM