最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

apache2服務(wù)器的搭建和配置步驟詳解

 更新時(shí)間:2017年04月29日 11:30:27   作者:Myths  
其實(shí)搭建apache2并不難,只是網(wǎng)上的資料有很多都過時(shí)了,之前被誤導(dǎo)過好幾次,走了很多彎路。趁著這次在本地搭建網(wǎng)站的時(shí)機(jī)重新捋一下思路,也方便以后有需求的時(shí)候查閱,需要的朋友可以參考下。

前言

這篇文章主要給大家介紹了在linux下apache2服務(wù)器的搭建和配置的相關(guān)資料,具有一定的參考價(jià)值,下面來一起學(xué)習(xí)學(xué)習(xí)吧。

步驟如下

首先當(dāng)然是下載包包:

myths@myths-X450LD:~$ sudo apt-get install apache2

裝完后就可以用了,在地址欄輸入本地回送地址127.0.0.1或者localhost就可以進(jìn)入到默認(rèn)的界面了。

默認(rèn)的界面當(dāng)然就是apache2的說明界面了。其實(shí)很多情況下并不需要在網(wǎng)上尋找?guī)椭臋n,幾乎所有的軟件都會(huì)自帶使用說明,只是略長(zhǎng),我們一般都懶得看。但是其實(shí)很多重要的東西就在這當(dāng)中,比如apache2的默認(rèn)界面里:

Ubuntu Logo Apache2 Ubuntu Default Page
It works!
This is the default welcome page used to test the correct operation of the Apache2 server after installation on Ubuntu systems. It is based on the equivalent page on Debian, from which the Ubuntu Apache packaging is derived. If you can read this page, it means that the Apache HTTP server installed at this site is working properly. You should replace this file (located at /var/www/html/index.html) before continuing to operate your HTTP server.
If you are a normal user of this web site and don't know what this page is about, this probably means that the site is currently unavailable due to maintenance. If the problem persists, please contact the site's administrator.
Configuration Overview
Ubuntu's Apache2 default configuration is different from the upstream default configuration, and split into several files optimized for interaction with Ubuntu tools. The configuration system is fully documented in /usr/share/doc/apache2/README.Debian.gz. Refer to this for the full documentation. Documentation for the web server itself can be found by accessing the manual if the apache2-doc package was installed on this server.
The configuration layout for an Apache2 web server installation on Ubuntu systems is as follows:
/etc/apache2/
|-- apache2.conf
|  `-- ports.conf
|-- mods-enabled
|  |-- *.load
|  `-- *.conf
|-- conf-enabled
|  `-- *.conf
|-- sites-enabled
|  `-- *.conf
apache2.conf is the main configuration file. It puts the pieces together by including all remaining configuration files when starting up the web server.
ports.conf is always included from the main configuration file. It is used to determine the listening ports for incoming connections, and this file can be customized anytime.
Configuration files in the mods-enabled/, conf-enabled/ and sites-enabled/ directories contain particular configuration snippets which manage modules, global configuration fragments, or virtual host configurations, respectively.
They are activated by symlinking available configuration files from their respective *-available/ counterparts. These should be managed by using our helpers a2enmod, a2dismod, a2ensite, a2dissite, and a2enconf, a2disconf . See their respective man pages for detailed information.
The binary is called apache2\. Due to the use of environment variables, in the default configuration, apache2 needs to be started/stopped with /etc/init.d/apache2 or apache2ctl. Calling /usr/bin/apache2 directly will not work with the default configuration.
Document Roots
By default, Ubuntu does not allow access through the web browser to any file apart of those located in /var/www, public_html directories (when enabled) and /usr/share (for web applications). If your site is using a web document root located elsewhere (such as in /srv) you may need to whitelist your document root directory in /etc/apache2/apache2.conf.
The default Ubuntu document root is /var/www/html. You can make your own virtual hosts under /var/www. This is different to previous releases which provides better security out of the box.
Reporting Problems
Please use the ubuntu-bug tool to report bugs in the Apache2 package with Ubuntu. However, check existing bug reports before reporting a new bug.
Please report bugs specific to modules (such as PHP and others) to respective packages, not to the web server itself.
Valid XHTML 1.0 Transitional

僅僅從這個(gè)文件中,我們就可以至少得到以下的重要信息:

  • 當(dāng)訪問本機(jī)的時(shí)候,默認(rèn)進(jìn)入的頁面是/var/www/html/index.html。
  • 配置系統(tǒng)的說明在/usr/share/doc/apache2/README.Debian.gz中。
  • 完整使用手冊(cè)可以通過安裝apache2-doc 進(jìn)行下載。
  • 主配置文件為/etc/apache2/apache2.conf。
  • 啟動(dòng)和關(guān)閉apache2服務(wù)可以通過執(zhí)行命令/etc/init.d/apache2 start(stop / restart)當(dāng)然也可以是 service apache2 start (stop / restart)。這里一定要注意記得!記得!加root權(quán)限!這里不加root權(quán)限并沒有明顯的提示(好坑),當(dāng)遇到問題的時(shí)候很難讓人想到是這里出的錯(cuò),所以一定要記得!記得!加root權(quán)限!
  • 默認(rèn)情況下apache2拒絕訪問除/var/www 和/usr/share文件夾外的其他文件,這種權(quán)限是通過apache2.conf文件來控制的.

默認(rèn)的apache2.conf為:

# This is the main Apache server configuration file. It contains the
# configuration directives that give the server its instructions.
# See http://httpd.apache.org/docs/2.4/ for detailed information about
# the directives and /usr/share/doc/apache2/README.Debian about Debian specific
# hints.
#
#
# Summary of how the Apache 2 configuration works in Debian:
# The Apache 2 web server configuration in Debian is quite different to
# upstream's suggested way to configure the web server. This is because Debian's
# default Apache2 installation attempts to make adding and removing modules,
# virtual hosts, and extra configuration directives as flexible as possible, in
# order to make automating the changes and administering the server as easy as
# possible.
# It is split into several files forming the configuration hierarchy outlined
# below, all located in the /etc/apache2/ directory:
#
# /etc/apache2/
# |-- apache2.conf
# | `-- ports.conf
# |-- mods-enabled
# | |-- *.load
# | `-- *.conf
# |-- conf-enabled
# | `-- *.conf
# `-- sites-enabled
# `-- *.conf
#
#
# * apache2.conf is the main configuration file (this file). It puts the pieces
# together by including all remaining configuration files when starting up the
# web server.
#
# * ports.conf is always included from the main configuration file. It is
# supposed to determine listening ports for incoming connections which can be
# customized anytime.
#
# * Configuration files in the mods-enabled/, conf-enabled/ and sites-enabled/
# directories contain particular configuration snippets which manage modules,
# global configuration fragments, or virtual host configurations,
# respectively.
#
# They are activated by symlinking available configuration files from their
# respective *-available/ counterparts. These should be managed by using our
# helpers a2enmod/a2dismod, a2ensite/a2dissite and a2enconf/a2disconf. See
# their respective man pages for detailed information.
#
# * The binary is called apache2\. Due to the use of environment variables, in
# the default configuration, apache2 needs to be started/stopped with
# /etc/init.d/apache2 or apache2ctl. Calling /usr/bin/apache2 directly will not
# work with the default configuration.
# Global configuration
#
#
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# NOTE! If you intend to place this on an NFS (or otherwise network)
# mounted filesystem then please read the Mutex documentation (available
# at <URL:http://httpd.apache.org/docs/2.4/mod/core.html#mutex>);
# you will save yourself a lot of trouble.
#
# Do NOT add a slash at the end of the directory path.
#
#ServerRoot "/etc/apache2"
#
# The accept serialization lock file MUST BE STORED ON A LOCAL DISK.
#
Mutex file:${APACHE_LOCK_DIR} default
#
# PidFile: The file in which the server should record its process
# identification number when it starts.
# This needs to be set in /etc/apache2/envvars
#
PidFile ${APACHE_PID_FILE}
#
# Timeout: The number of seconds before receives and sends time out.
#
Timeout 300
#
# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.
#
KeepAlive On
#
# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.
#
MaxKeepAliveRequests 100
#
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
#
KeepAliveTimeout 5
# These need to be set in /etc/apache2/envvars
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
#
# HostnameLookups: Log the names of clients or just their IP addresses
# e.g., www.apache.org (on) or 204.62.129.132 (off).
# The default is off because it'd be overall better for the net if people
# had to knowingly turn this feature on, since enabling it means that
# each client request will result in AT LEAST one lookup request to the
# nameserver.
#
HostnameLookups Off
# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
# container, error messages relating to that virtual host will be
# logged here. If you *do* define an error logfile for a <VirtualHost>
# container, that host's errors will be logged there and not here.
#
ErrorLog ${APACHE_LOG_DIR}/error.log
#
# LogLevel: Control the severity of messages logged to the error_log.
# Available values: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the log level for particular modules, e.g.
# "LogLevel info ssl:warn"
#
LogLevel warn
# Include module configuration:
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
# Include list of ports to listen on
Include ports.conf
# Sets the default security model of the Apache2 HTTPD server. It does
# not allow access to the root filesystem outside of /usr/share and /var/www.
# The former is used by web applications packaged in Debian,
# the latter may be used for local directories served by the web server. If
# your system is serving content from a sub-directory in /srv you must allow
# access here, or in any related virtual host.
<Directory />
 Options FollowSymLinks
 AllowOverride None
 Require all denied
</Directory>
<Directory /usr/share>
 AllowOverride None
 Require all granted
</Directory>
<Directory /var/www/>
 Options Indexes FollowSymLinks
 AllowOverride None
 Require all granted
</Directory>
#<Directory /srv/>
# Options Indexes FollowSymLinks
# AllowOverride None
# Require all granted
#</Directory>
# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives. See also the AllowOverride
# directive.
#
AccessFileName .htaccess
#
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<FilesMatch "^.ht">
 Require all denied
</FilesMatch>
#
# The following directives define some format nicknames for use with
# a CustomLog directive.
#
# These deviate from the Common Log Format definitions in that they use %O
# (the actual bytes sent including headers) instead of %b (the size of the
# requested file), because the latter makes it impossible to detect partial
# requests.
#
# Note that the use of %{X-Forwarded-For}i instead of %h is not recommended.
# Use mod_remoteip instead.
#
LogFormat "%v:%p %h %l %u %t "%r" %>s %O "%{Referer}i" "%{User-Agent}i"" vhost_combined
LogFormat "%h %l %u %t "%r" %>s %O "%{Referer}i" "%{User-Agent}i"" combined
LogFormat "%h %l %u %t "%r" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
# Include of directories ignores editors' and dpkg's backup files,
# see README.Debian for details.
# Include generic snippets of statements
IncludeOptional conf-enabled/*.conf
# Include the virtual host configurations:
IncludeOptional sites-enabled/*.conf
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

注意這當(dāng)中的一段:

<Directory />
 Options FollowSymLinks
 AllowOverride None
 Require all denied
</Directory>
<Directory /usr/share>
 AllowOverride None
 Require all granted
</Directory>
<Directory /var/www/>
 Options Indexes FollowSymLinks
 AllowOverride None
 Require all granted
</Directory>

由這段可以很容易的知道apache2到底為哪些文件夾賦予了打開的權(quán)限了。以后就可以通過修改這里達(dá)到各種不可告人的目的了。

最后還有一個(gè)重要的配置,就是默認(rèn)目錄的更改。默認(rèn)的目錄其實(shí)是記錄在:/etc/apache2/sites-available/000-default.conf 文件當(dāng)中(在/etc/apache2/sites-enable/中也有一個(gè)指向他的鏈接):

myths@myths-X450LD:/etc/apache2/sites-available$ cat 000-default.conf 
<VirtualHost *:80>
 # The ServerName directive sets the request scheme, hostname and port that
 # the server uses to identify itself. This is used when creating
 # redirection URLs. In the context of virtual hosts, the ServerName
 # specifies what hostname must appear in the request's Host: header to
 # match this virtual host. For the default virtual host (this file) this
 # value is not decisive as it is used as a last resort host regardless.
 # However, you must set it for any further virtual host explicitly.
 #ServerName www.example.com
 ServerAdmin webmaster@localhost
 DocumentRoot /var/www/html
 # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
 # error, crit, alert, emerg.
 # It is also possible to configure the loglevel for particular
 # modules, e.g.
 #LogLevel info ssl:warn
 ErrorLog ${APACHE_LOG_DIR}/error.log
 CustomLog ${APACHE_LOG_DIR}/access.log combined
 # For most configuration files from conf-available/, which are
 # enabled or disabled at a global level, it is possible to
 # include a line for only one particular virtual host. For example the
 # following line enables the CGI configuration for this host only
 # after it has been globally disabled with "a2disconf".
 #Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

當(dāng)中的“DocumentRoot ”鍵對(duì)應(yīng)的值就是默認(rèn)的目錄了,可以任由我們修改了。

apache2的簡(jiǎn)單配置基本就是這些,不需要百度,我們也是完全可以自己弄清楚的。

注:

  • 修改完配置文件后記得重啟服務(wù)
  • 可以順手吧/var/www的權(quán)限設(shè)置為777方便修改網(wǎng)頁

總結(jié)

以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對(duì)腳本之家的支持。

相關(guān)文章

  • ubuntu下編譯安裝opencv的方法

    ubuntu下編譯安裝opencv的方法

    今天小編就為大家分享一篇關(guān)于ubuntu下編譯安裝opencv的方法,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧
    2019-04-04
  • Linux如何關(guān)閉無用端口

    Linux如何關(guān)閉無用端口

    本文介紹了如何在Linux系統(tǒng)中關(guān)閉無用端口,以提高系統(tǒng)安全性,以關(guān)閉111端口為例,詳細(xì)說明了查看監(jiān)聽端口、確定服務(wù)、查看服務(wù)詳細(xì)信息、關(guān)閉服務(wù)并設(shè)置開機(jī)不啟動(dòng),最后提供了關(guān)閉其他端口的總結(jié)
    2024-12-12
  • 如何在Linux下設(shè)置錄音筆時(shí)間

    如何在Linux下設(shè)置錄音筆時(shí)間

    這篇文章主要介紹了如何在Linux下設(shè)置錄音筆時(shí)間的方法,有這方面需要的朋友跟著學(xué)習(xí)下吧。
    2017-12-12
  • 關(guān)于Windows 不能在 本地計(jì)算器 啟動(dòng) Apache2(phpstudy)

    關(guān)于Windows 不能在 本地計(jì)算器 啟動(dòng) Apache2(phpstudy)

    今天在自己的本子上準(zhǔn)備放多個(gè)虛擬站點(diǎn)。用的是#phpstudy#。在軟件自身的站點(diǎn)設(shè)置中,根據(jù)提示添加的多站點(diǎn)無效不知道是否和我的系統(tǒng)是Win7有關(guān)
    2012-09-09
  • Linux使用systemd服務(wù)和crontab實(shí)現(xiàn)Shell腳本開機(jī)自動(dòng)運(yùn)行過程

    Linux使用systemd服務(wù)和crontab實(shí)現(xiàn)Shell腳本開機(jī)自動(dòng)運(yùn)行過程

    在Linux系統(tǒng)中,使用systemd和crontab是實(shí)現(xiàn)Shell腳本開機(jī)自啟動(dòng)的兩種常用方法,首先,需創(chuàng)建一個(gè)Shell腳本,將其放置在適當(dāng)目錄,通過編寫.service文件并將其移動(dòng)到/etc/systemd/system/目錄下,可以設(shè)置為systemd服務(wù)
    2024-09-09
  • 安裝ubuntu18.04報(bào):failed to load ldlinux.c32的問題及解決步驟

    安裝ubuntu18.04報(bào):failed to load ldlinux.c32的問題及解決步驟

    這篇文章主要介紹了安裝ubuntu18.04報(bào):failed to load ldlinux.c32的問題,本文通過圖文并茂的形式給大家分享解決方法,需要的朋友可以參考下
    2020-08-08
  • kali?linux?無法登錄root的問題及解決方法

    kali?linux?無法登錄root的問題及解決方法

    這篇文章主要介紹了kali?linux?無法登錄root的問題及解決方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧
    2025-04-04
  • CentOS7上以rpm方式安裝JDK8

    CentOS7上以rpm方式安裝JDK8

    這篇文章主要介紹了CentOS7上以rpm方式安裝JDK8,需要的朋友可以參考下
    2020-02-02
  • 5個(gè)提高Linux開發(fā)效率的工具

    5個(gè)提高Linux開發(fā)效率的工具

    這篇文章主要介紹了5個(gè)提高Linux開發(fā)效率的工具,能夠充分個(gè)性化并無縫地融入獨(dú)特工作流程的工具才是真正的好工具。想要知道哪五個(gè)Linux工具可以提高開發(fā)效率,請(qǐng)閱讀本文
    2015-12-12
  • 淺談Linux條件變量的使用

    淺談Linux條件變量的使用

    下面小編就為大家?guī)硪黄獪\談Linux條件變量的使用。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-01-01

最新評(píng)論

光山县| 德昌县| 尼玛县| 宝坻区| 昌乐县| 临海市| 伊春市| 佛冈县| 永宁县| 孟津县| 深泽县| 寻乌县| 巴里| 法库县| 揭阳市| 成安县| 泰宁县| 那坡县| 广州市| 凉城县| 汽车| 庆城县| 前郭尔| 大理市| 巴青县| 大悟县| 二连浩特市| 宜黄县| 祁东县| 沽源县| 襄城县| 清河县| 丰都县| 合肥市| 宣威市| 临海市| 新田县| 桃园县| 蕲春县| 丽江市| 汝南县|