啓動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/