Install apache in ubuntu
sudo apt-get install apache2
The resulting start and stop files are:/etc/init.d/apache2
sudo apache2ctl -k start
sudo apache2ctl -k stop
sudo apache2ctl -k restart
The configuration file is stored in:/etc/apache2
It should be noted,The general Apache distribution configuration file is:httpd.conf
The main configuration file of the ubuntu distribution is:apache2.conf
The following files are referenced in apache2.conf:
#Contains the configuration of dynamic modules: include /etc/apache2/mods-enabled/*.load include /etc/apache2/mods-enabled/*.conf #Contains the user's own configuration: include /etc/apache2/httpd.conf #Contains port listening configuration: include /etc/apache2/ports.conf #Contains general snippets of configuration statements: include /etc/apache2/conf.d/ #Contains the configuration instructions for the virtual host: include/etc/apache2/sites-enabled /
Add the following:
ubuntu apache2 configuration
1.apache2.conf is the main configuration file,httpd.conf user configuration file
2. The virtual directory is in httpd.conf
<virtualhost *> documentroot "path" servername name <directory "path">allow from all options + indexes</directory> </virtualhost>
3. The root setting (default home directory) is in/etc/apache2/sites-available/default
4. Restart command
sudo /etc/init.d/apache2 restart or cd /etc/init.d sudo apache2 -k restart
stop Stop;start 5. The log file is at/var/log/apache2 /
<virtualhost *:80> servername www.kimoqi.com documentroot/home/vsftpd/kimoqi </virtualhost> <virtualhost *:80> servername www.arwenedu.com documentroot/home/vsftpd/wangguan/webapps </virtualhost> <virtualhost *:80> servername www.arwenedu.org.cn documentroot/home/vsftpd/wangguan/chem </virtualhost>
Under Windows, there is usually only one configuration file for Apache.This is httpd.conf. But after I installed apache2 with apt-get install apache2 on ubuntu linux, I found that its httpd.conf (located in the/etc/apache2 directory) was empty! It was found that the configuration file of the ubuntu apache package is not as simple as that of windows.It divides each setting item into different configuration files.Looks complicated,But thinking about it is really reasonable.
Strictly speaking,The configuration file of ubuntu's apache (or should be apache under linux?I don't know the apache packages of other distributions) is /etc/apache2/apache2.conf, and Apache will automatically read the configuration information of this file when it starts.And some other configuration files,For example, httpd.conf is included through the include directive.These include lines can be found in apache2.conf:
#include module configuration: include /etc/apache2/mods-enabled/*.load include /etc/apache2/mods-enabled/*.conf #include all the user configurations: include /etc/apache2/httpd.conf #include ports listing include /etc/apache2/ports.conf ... #include generic snippets of statements include /etc/apache2/conf.d/ #include the virtual host configurations: include/etc/apache2/sites-enabled /
Combined with comments,You can clearly see the general role of each profile.Of course, you can put all the settings in apache2.conf or httpd.conf or any configuration file.This division of apache2 is just a good habit.
The most important thing after installing Apache is to know where the web document root directory is.For Ubuntu, the default is/var/www. How do you know?There is no documentroot entry in apache2.conf, and httpd.conf is empty again.So it must be in other documents.After searching,Found in/etc/apache2/sites-enabled/000-default, there is something like this:
namevirtualhost * <virtualhost *> serveradmin [email protected] documentroot/var/www / ...
This is setting up a virtual host,Doesn't make much sense to me.So I commented out the include/etc/apache2/sites-enabled/line in apache2.conf,And set documentroot as a directory under my user directory in httpd.conf, which is convenient for development.
Look at the contents of the/etc/apache2 directory.I just found the sites-enabled directory in apache2.conf, and there is also a sites-available directory under/etc/apache2. Actually, this is the real configuration file.The sites-enabled directory stores only symbolic links to the files here,You can verify this with ls/etc/apache2/sites-enabled /.So if multiple virtual hosts are configured on apache,The configuration file of each virtual host is placed under sites-available, so it is very convenient to disable and enable the virtual host:when a link to a virtual host configuration file is established under sites-enabled, it is enabled Got itIf i want to shut down a virtual host,Just delete the link,No need to change the configuration file at all.
mods-available and mods-enabled are similar to the sites-available and sites-enabled mentioned above. These two directories store the configuration files and links of the apache function modules.When I installed the php module using apt-get install php5, there were php5.load, php5.conf and links to these two files in these two directories.This directory result is very convenient for enabling and disabling an apache module.
The last thing to say is ports.conf, which sets the ports used by Apache.If you need to adjust the default port settings,It is recommended to edit this file.Or if you think it is more than enough, you can also remove the include /etc/apache2/ports.conf line in apache2.conf first.Set the apache port in httpd.conf.
The directory structure of the default installation in ubuntu is a little different.There are two directories for module and virtual host configuration in ubuntu.One is available, the other is enabled. The available directory is used to store valid content.But doesn't work,Only works with ln connected to enabled in the past.Easy to debug and use,But if you do n’t know in advance,It's also a bit troublesome to find.
/etc/apache2/sites-available puts the configuration of vh, but does not work,You need to link the file into the sites-enabled directory.
<virtualhost *> servername domain name documentroot uses public in the rails project as the root directory <directory public root directory> options execcgi followsymlinks allowoverride all allow from all order allow, deny </directory> errorlog/var/log/apache2/error-domain log </virtualhost>
Further configuration and use,You can consult the apache manual
Apache configuration file httpd.conf description
documentroot "/var/www/html" --- apache default server home directory path
directoryindex index.html index.htm index.php index.html.var --- the default document,Separate multiple files with spaces
listen 192.168.1.1:80 Set the address and port of the listening IP to 192.168.1.1 to 80
listen 192.168.1.2:8080 Set the address and port of the listening IP to 192.168.1.2 to 8080
serverroot "/etc/httpd" sets the path relative to the root directory, usually refers to the place where the configuration files and log files are stored.The default is:/etc/httpd generally includes conf and logs subdirectories
errorlog logs/error_log Set the error log Note:If the log file storage path does not start with "/", it means that the file is relative to the serverroot directory
customlog logs/access_log combined access log (combined indicates the format used by the log,And common format)
servername Set the server host name (if there is a domain name, you can enter the domain name,(If there is no domain name, you can enter the server IP address)
adddefaultcharset gb2312 set the default character set,Defines the default character set returned by the server to the client (since Western European UTF-8 is the apache default character set,So when you visit a webpage with Chinese, garbled characters will appear.At this time, just change the character set to gb2312, and then restart the apache service)
alias/down "/software/download" creates a virtual directory (creates a virtual directory named down,Its corresponding physical path is:/software/download)
alias/ftp "/var/ftp" creates a virtual directory (creates a virtual directory named ftp,Its corresponding physical path is:/var/ftp)
<directory "/var/www/html">Set directory permissions (<directory "directory path">This time write the statement to set directory permissions</directory>) options followsymlinks page:116 allowoverride none </directory>
Domain-based web hosting
namevirtualhost 22.214.171.124 --- first use the namevirtualhost command to specify which IP address is responsible for responding to requests for virtual hosts
<virtualhost www.iigoogle.com> servername www.iigoogle.com:80 serveradmin [email protected] documentroot/www/docs/iigoogle directoryindex index.jsp errorlog logs/www/iigoogle/error_log customlog logs/www/iigoogle/access_log common </virtualhost>
<virtualhost www.iigoogle.com:80> servername www.iigoogle.com serveradmin [email protected] documentroot /www/docs/iigoogle.com errorlog logs/www/iigoogle/error_log customlog logs/www/iigoogle/access_log common </virtualhost>
- How to install Apache Tomcat on Ubuntu 1604
- Ubuntu 1404 tutorial for installing Apache Ant
- Graphic tutorial for installing mysql8011 on Ubuntu1804
- Detailed process of installing PHP 7 under Ubuntu 1604
- Graphical tutorial for installing LAMP on Ubuntu Server 1604 LTS
- A complete tutorial on installing Apache, MySQL, PHP, LAMP on Ubuntu 1804
- Git repository using redmine authentication does not work properly
- ubuntu : Mercurial TortoiseHG Error 255
- Listening and maintaining the same port in Apache on UBuntu OS 20.04
- PHP does not read code with
- i can't open it with "403 forbidden" after installing phpmyadmin
- php - about apache virtual host settings
- since the ports used by apache2 and xampp are the same, basic authentication and web page display cannot be done at the same tim
- php - if you change the site address on wordpress, it will redirect to other domains without permission
- start apache2 on ubuntu 2004 and display the created html
- ubuntu+docker cannot create php environment