场景二:http服务器
一、配置静态页面
1、直接解压后,在/usr/local/nginx/html/ 下创建个www目录,然后在目录下放一个test.html
2、nginx.conf 中server的配置
http {
server {
#监听端口
listen 80;
#服务名称用于配置域名
server_name localhost;
client_max_body_size 1024M;
# 默认location
location / {
root /usr/local/nginx/html/www;
index index.html index.htm;
}
}
}
3、访问
-
http://localhost/ 指向/usr/local/nginx/html/index.html, index.html 是安装Nginx自带的html
-
http://localhost/test.html指向/usr/local/nginx/html/www/test.html
说明:如果访问出现403,可能是因为#user nobody 被注释,改成对应的组用户,然后重启
location解释:
a)root是根路径,当访问 http://localhost/test.html,"/test.html"会匹配到"/",
找到root /usr/local/nginx/html/www,用户访问的资源是/