1. 問題具體描述
我在centos7下搭建好了appache服務器,然后寫好了后台程序以及前端網頁,現在想用我的筆記本建立一個熱點,然后用我的手機連接並訪問我的網站。 我嘗試了下,發現要么是找不到網頁,要么是訪問人數過多或無法訪問(但在我的電腦上可以訪問我的網站)。 心很涼~
2. 期間使用的工具
系統是centos7, 服務器是appache, 用的是C寫了CGI后台程序,用HTML5寫了前端網頁。
3. 如何能訪問的?
我考慮到防火牆是不是禁止了外界對我的網站的訪問, 后來百度下,找到了解決辦法。
切換root模式,輸入shell指令: firewall-cmd --permanent --add-service=http (意思是 防火牆永久開放http服務)
然后,重啟firewall-cmd: firewall-cmd --reload
另外,下面是我httpd.conf的配置,主要是三部分,一個是設置我的wifi熱點的監聽(畢竟要把我的電腦作為服務器),一個是把/var/www/html開放出來,還有一個是/var/www/cgi-bin,
因為我要訪問我的網頁和后台程序。
部分1
# # Listen: Allows you to bind Apache to specific IP addresses and/or # ports, instead of the default. See also the <VirtualHost> # directive. # # Change this to Listen on specific IP addresses as shown below to # prevent Apache from glomming onto all bound IP addresses. # #Listen 12.34.56.78:80 Listen 10.42.0.1:80 #讓服務器監聽IP是10.42.0.1,網站的端口80,這個IP是我的wifi模塊的IP
部分2
# Further relax access to the default document root: <Directory "/var/www/html"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/2.4/mod/core.html#options # for more information. # Options Indexes FollowSymLinks # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride None Order allow,deny # # Controls who can get stuff from this server. # # Require all granted Allow from all </Directory>
部分3
# # "/var/www/cgi-bin" should be changed to whatever your ScriptAliased # CGI directory exists, if you have that configured. # <Directory "/var/www/cgi-bin"> AllowOverride None Options ExecCGI #執行CGI Order allow,deny Allow from all AddHandler default-handler .css </Directory>
更改配置后,重啟appache服務器: systemctl restart httpd
4. 備注
如果有什么問題,多多指教,謝謝。