启动nginx
# 启动
systemctl restart nginx;
# 报错了,查看报错信息
systemctl status nginx;
错误提示为这两句:
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx[5640]: nginx: [emerg] still could not bind()
很明显,80端口被占用了。 是https服务占用的。
# 查看端口
netstat -nltp | grep 80;
# kill掉pid
kill -9 555;
# 再次查看
netstat -nltp | grep 80;
# 发现没有杀掉,用systemctl停掉
systemctl stop https;
systemctl restart nginx; 不报错说明启动成功。
浏览器输如网址,看到nginx界面。
搭建静态服务器
创建目录:
mkdir -p /www/static ;
cd /www/static;
vim index.html; 输入如下内容:
<html lang="zh">
<body>
welcome
</body>
</html>
配置/etc/nginx/nginx.conf ,修改server模块:
server {
listen 80 ;
server_name 47.104.176.200;
root /www/static-web;
index index.html index.htm;
location / {
root /www/static-web;
}
}
重启nginx 。
浏览器访问服务器地址,显示welcome说明成功。
报错 nginx: [emerg] invalid parameter “localhost” in /etc/nginx/nginx.conf:39
说明配置不对。
其他
官网文档(不太容易看懂):
http://nginx.org/en/docs/