include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; }
include /etc/nginx/sites-enabled/*;是最重要的。
include /etc/nginx/sites-enabled/*
在 Nginx 中,文件加载和生效的顺序是由 include 指令定义的。如果在这些文件中有重复的配置,后加载的配置将覆盖先加载的配置。因此,后加载的配置文件具有更高的优先级。
默认server块在/etc/nginx/sites-enabled/default
默认填写了root /var/www/html;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
server { listen 80 default_server;
root /var/www/html;
# Add index.php to the list if you are using PHP index index.php index.html index.htm index.nginx-debian.html;
server_name _;
location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; } }
新配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# Virtual Host configuration for example.com # # You can move that to a different file under sites-available/ and symlink that # to sites-enabled/ to enable it. # server { listen 80; listen [::]:80;
You should replace this file (located at /var/www/html/index.html) before continuing to operate your HTTP server.
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:
* **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`. * 最简单实现`mount -t none -o bind,ro /targetPath /var/www/html` * 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. {% endmessage %}
## 遇到的问题
{% message color:danger "icon:fa-solid fa-xmark" "title:You don't have permission to access / on this server." %} 把静态网页传上去
```sh $ sudo apache2ctl -k restart AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
没有访问权限
1 2
Forbidden You don't have permission to access / on this server.
这是因为没有修改运行访问的目录,而且能通过别名
title
1 2 3 4 5 6
alias /testtsj/ "/home/shaojiemike/Network/" <Directory "/home/shaojiemike/Network/"> Options Indexes FollowSymLinks #首页不存在,允许访问当前目录下其它内容 AllowOverride None Require all granted #允许访问所有 </Directory>