WIKI使用導航
站長百科導航
站長專題
- 網(wǎng)站推廣
- 網(wǎng)站程序
- 網(wǎng)站賺錢
- 虛擬主機
- cPanel
- 網(wǎng)址導航專題
- 云計算
- 微博營銷
- 虛擬主機管理系統(tǒng)
- 開放平臺
- WIKI程序與應用
- 美國十大主機
CentOS/開放一般用戶的網(wǎng)頁發(fā)布權限
CentOS | CentOS安裝 | CentOS使用手冊 |
當我們想發(fā)布網(wǎng)頁的時候,通常找一些免費空間,將我們的網(wǎng)頁等等放在那個免費空間上。通常,我們申請到的免費空間的訪問方式通常是通過“http: //www.sample.com/~user”方式的。
其中“user”通常為申請時提交的用戶名。實質(zhì)上,在Linux下,Apache服務器擁有讓 一般用戶發(fā)布網(wǎng)頁的功能。我們要做的也只是更改Apache配置文件httpd.conf中的一些設置而已。
對于一般用戶來說,在用戶目錄中建立相應的子目錄,將這個子目錄作為對外開放的Web根目錄,并設置相應目錄的相應屬性,即可達到與服務器單獨發(fā)布(把網(wǎng)頁放在/var/www/html下)達到同樣的效果。而且,本條目配置完成的服務器,也完全可以為別人提供網(wǎng)頁存放、發(fā)布等等的服務。
修改Apache的配置文件[ ]
首先來修改Apache的配置文件,使Apache支持通過一般用戶目錄發(fā)布網(wǎng)頁的功能。
[root@sample ~]# vi /etc/httpd/conf/httpd.conf ← 用vi打開SSH的配置文件 UserDir disable ← 找到這一行,在行首增加“#” ↓ #UserDir disable ← 修改后變?yōu)榇藸顟B(tài) #UserDir public_html ← 找到這一行,去掉行首的“#” UserDir public_html ← 修改后變?yōu)榇螤顟B(tài) 找到下面水平線之間的部分行,將每行行首的“#”去掉,并在一些細節(jié)選項上按提示做修改 ------------------------------------------------------------------------------- #<Directory /home/*/public_html> # AllowOverride FileInfo AuthConfig Limit ← 找到此行,將相應選項刪除后,賦予All選項 ↓ AllowOverride All ← 變?yōu)榇藸顟B(tài),允許使用.htaccess # Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec ← 找到此行,將相應選項刪除 ↓ Options IncludesNoExec ExecCGI FollowSymLinks ← 變?yōu)榇藸顟B(tài),允許執(zhí)行CGI及SSI # <Limit GET POST OPTIONS> # Order allow,deny # Allow from all # </Limit> # <LimitExcept GET POST OPTIONS> # Order deny,allow # Deny from all # </LimitExcept> #</Directory> ------------------------------------------------------------------------------- ↓ 以上水平線之間的部分修改后,變?yōu)槿缦聽顟B(tài),尤其注意不要忘記將沒行行首的“#”去掉!請核對。 ------------------------------------------------------------------------------- <Directory /home/*/public_html> AllowOverride All Options IncludesNoExec ExecCGI FollowSymLinks <Limit GET POST OPTIONS> Order allow,deny Allow from all </Limit> <LimitExcept GET POST OPTIONS> Order deny,allow Deny from all </LimitExcept> </Directory> -------------------------------------------------------------------------------
重新啟動HTTP服務[ ]
重新啟動HTTP服務,使以上的設置生效。
[root@sample ~]# /etc/rc.d/init.d/httpd restart ← 重新啟動HTTP服務
一般用戶的Web目錄及相應屬性的設置[ ]
一般用戶對外開放Web,需要建立一般用戶專用的Web目錄,這里根據(jù)httpd.conf設置文件中的設置,需要將用戶Web目錄命名為“public_html”,并建立在一般用戶的根目錄下。一般用戶的根目錄屬性也要設置為711。
在這里以centospub為例,假設系統(tǒng)中,欲開放名為centospub的用戶對外開放Web的權限,其設置過程如下。
[root@sample ~]# chmod 711 /home/centospub/ ← 將欲開放Web的用戶目錄屬性設置為711 [root@sample ~]# su - centospub ← 登錄為欲開放Web的一般用戶 [root@sample ~]# cd ← 到用戶根目錄 [centospub@sample ~]$ mkdir public_html ← 在用戶根目錄下建立Web目錄,名為“public_html” [centospub@sample ~]$ chmod 755 public_html ← 將用Web目錄的屬性設置為755
然后,讓每建立新用戶的時候,用戶目錄下都能自動建立Web開放用的public_html目錄,使得每個用戶都有開放Web的機會。
[centospub@sample ~]# su - ← 再次登錄為root用戶 Password: ← 在這里輸入密碼 [root@sample ~]# mkdir /etc/skel/public_html ← 建立相應目錄,從而使得public_html自動建立 [root@sample ~]# exit ← 退出root登錄,返回一般用戶(這里以返回centospub用戶登錄為例)
對用戶Web支持進行全面測試[ ]
[1] 對HTML格式網(wǎng)頁正確顯示的測試
[centospub@sample ~]# vi /home/centospub/public_html/index.html ← 在用戶Web目錄下建立測試頁,如下: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=GB2312"> <title>Hello,World</title> <body> Hello,World! </body> </html>
然后在瀏覽器中輸入“http://服務器IP地址/~相應用戶名”或者“http://你的域名/~相應用戶名”,如果出現(xiàn)“Hello,World!”,并且瀏覽器讀取編碼為簡體中文,就OK。
注:用戶名前面不要忘了加上“ ~ ”符號。
[centospub@sample ~]# rm -f /var/www/html/index.html ← 刪除測試頁
[2] 對CGI的支持進行測試
[centospub@sample ~]# vi /home/centospub/public_html/test.cgi ← 在用戶Web目錄下建立測試頁,如下: #!/usr/bin/perl print "Content-Type: text/html\n\n"; print "<html><body>"; print "Hello,World!CGI is working!<br>"; print "</body></html>"; [centospub@sample ~]# chmod 755 /home/centospub/public_html/test.cgi ← 更改CGI測試文件的
然后在瀏覽器中輸入“http://服務器IP地址/~相應用戶名/test.cgi”或者“http: //你的域名/~相應用戶名/test.cgi”,如果正確顯示“Hello,World!CGI is working!”,說明用戶Web目錄對于CGI的支持沒有問題。
[3] 對PHP的支持進行測試
[centospub@sample ~]# vi /home/centospub/public_html/test.php ← 建立PHP測試文件,內(nèi)容如下: <?php phpinfo(); ?>
然后在瀏覽器中輸入“http://服務器IP地址/~相應用戶名/test.php”或者“http://你的域名/~相應用戶名/test.php”后,正確的顯示出了服務器上PHP的詳細信息,說明用戶Web目錄對PHP可以正確的支持。
[4] 對SSI的支持進行測試
[centospub@sample ~]# vi /home/centospub/public_html/test.shtml ← 在用戶Web目錄下建立SSI測試頁,如下: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=GB2312"> <title>Hello,World!</title> <body> TEST SSI <!--#config timefmt="%Y/%m/%d %H:%M:%S" --> <!--#echo var="DATE_LOCAL" --> </body> </html>
然后在瀏覽器中輸入“http://服務器IP地址/~相應用戶名/test.shtml”或者“http://你的域名/~相應用戶名/test.shtml”,如果正確顯示當時的日期和時間,說明用戶Web目錄對于SSI的支持沒有問題。
[5] 對.htaccess的支持進行測試
[centospub@sample ~]# vi /home/centospub/public_html/index.shtml ← 建立.htaccess測試用的頁,內(nèi)容如下: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=GB2312"> <title>Hello,World!</title> <body> The name of the file is <!--#echo var="DOCUMENT_NAME" --> </body> </html>
然后在瀏覽器中輸入“http://服務器IP地址/~相應用戶名/”或者“http://你的域名/~相應用戶名/”,如果顯示“Forbidden”,說明.htaccess正常。
然后在用戶的Web目錄下建立一個.htaccess文件,并定義相應規(guī)則,如下:
[centospub@sample html]# vi /home/centospub/public_html/.htaccess ← 建立.htaccess文件,內(nèi)容如下: DirectoryIndex index.shtml
這時,再次在瀏覽器中輸入“http://服務器IP地址/~相應用戶名/”或者“http://你 的域名/~相應用戶名/”,如果正確顯示“ The name of the file is index.shtml”,說明.htaccess中的規(guī)則生效狀態(tài)。
[6] 刪除測試用的遺留文件
[centospub@sample ~]# rm -f /home/centospub/public_html/* /home/centospub/public_html/.htaccess ← 刪除測試用過的遺留文件 [centospub@sample ~]# exit ← 退出用戶登錄(回到root登錄的狀態(tài))
參考來源[ ]
http://www.centospub.com/make/userdirectory.html