系统Ubuntu 18
通过apt安装好nginx后,首先启动nginx进程
/etc/init.d/nginx start
然后了解一下几个重要的配置文件,首先用配置文件检查命令找一下配置文件nginx.conf
的位置:
sudo nginx -t
得到
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
用nano 或者别的编辑器打开/etc/nginx/nginx.conf
:
可以看见http服务器的设置:
http {
---省略---
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
---省略---
}
告诉我们生效的server配置文件放在/etc/nginx/sites-enabled/
里,稍后会用到。
现在创建一个示例的html文档,
nginx默认配置在/var/www/html
目录下提供文档,我们可以在它旁边新建一个目录:
sudo mkdir -p /var/www/example.com/html
确保这个目录权限是正确的:
sudo chmod -R 755 /var/www/example.com/
然后新建一个html文件,用编辑器编辑
/var/www/example.com/html/index.