ubuntu apache2 修改網頁端口

Apache 服務經常由於ISP將TCP默認80端口封鎖而無法正常運行,這時候就需要更改默認80端口爲一個指定的端口。比如修改爲8001.

1.進入/etc/apache2/ports.conf文件,按照下面紅色的部分修改:

#######################分割線#####################################

# If you just change the port or add more ports here, you will likely also

# have to change the VirtualHost statement in

# /etc/apache2/sites-enabled/000-default

#####上面的說明很重要!!!!

# This is also true if you have upgraded from before 2.2.9-3 (i.e. from

# Debian etch). See /usr/share/doc/apache2.2-common/NEWS.Debian.gz and

# README.Debian.gz

NameVirtualHost *:80

Listen 8001   

###上面的兩行默認爲80端口

<IfModule mod_ssl.c>

    # If you add NameVirtualHost *:443 here, you will also have to change

# the VirtualHost statement in /etc/apache2/sites-available/default-ssl

    # to <VirtualHost *:443>

    # Server Name Indication for SSL named virtual hosts is currently not

    # supported by MSIE on Windows XP.

    Listen 443

</IfModule>

<IfModule mod_gnutls.c>

    Listen 443

</IfModule>

#######################分割線#####################################

2.再進入/etc/apache2/sites-enabled/000-default文件,按如下紅色部分修改

#######################分割線#####################################

<VirtualHost *:8001>   ####這裏對應於新端口,默認爲80

ServerAdmin webmaster@localhost

DocumentRoot /var/www

<Directory />

####該文件餘下內容,省略大概4百字,嘿嘿

#######################分割線#####################################

然後,在終端中重啓apache(輸入sudo /etc/init.d/apache2 restart

在瀏覽器中輸入http://localhost:8001/或者自己的域名加端口號的方式訪問,比如我這裏就是http://phykingpeng.co.cc:8001/.就OK了!

Apache常見錯誤說明:

1.第2步若未執行容易出現404錯誤(Chrome提示:“Oops! This link appears to be broken.”錯誤。FireFox會提示Not Found The requested URL / was not found on this server.Apache/2.2.14 (Ubuntu) Server at localhost Port 8001,爲一個404Not Found錯誤。)

2.對於Apache,任何對配置文件的改變都需要重啓Apache服務,這個算是常識了!


在Ubuntu上安裝Apache,每次重啓,都會出現以下錯誤提示:

Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName

解決辦法
修改 httpd.conf 文件
打開終端,輸入以下命令:

sudo vim /etc/apache2/httpd.conf

默認情況下,這個是一個空文件,在文件中加入以下內容:

ServerName localhost

保存文件退出,再次重啓apache,錯誤提示沒有了。

Ubuntu10.04上apache2: bad user name ${APACHE_RUN_USER}問題解決

1. 安轉apache2

  # sudo apt-get install apache2

2. 安裝完畢後,使用命令“apache2 -k graceful”啓動的時候報以下錯誤

  apache2: bad user name ${APACHE_RUN_USER}

3. 檢查/etc/apache2/apache2.conf文件,發現其中需要使用/etc/apache2/envvars文件中的以下幾個環境變量

  export APACHE_RUN_USER=www-data

  export APACHE_RUN_GROUP=www-data

  export APACHE_PID_FILE=/var/run/apache2.pid

  但是在檢查這幾個環境變量時發現配置的用戶名合組都是存在的

4. 後來發現如果不用腳本而改用啓動系統服務的方式,就可以避免上面問題

  # sudo /etc/init.d/apache2

5. 將自己的html文件放置在/var/www/目錄下,然後訪問http://localhost/,一切ok!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章