编译nginx
1,在官网上下载nginx源码
wget https://nginx.org/download/nginx-1.8.0.tar.gz
2,解压,并 cd 到目录下
3,编译安装
./configure --prefix=/usr/local/nginx
make && make install
编译失败
是因为没有安装这些依赖
安装依赖包
yum install -y gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
之后再make
4,启动
cd 到 /usr/local/nginx/sbin ./ nginx
关闭命令
在/usr/local/nginx/sbin 目录下执行 ./nginx -s stop
重新加载命令
在/usr/local/nginx/sbin 目录下执行 ./nginx -s reload
报错,原因是端口问题
[root@localhost sbin]# ./nginx
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
查看开放的端口号
firewall-cmd --list-all
设置开放的端口号
firewall-cmd --add-service=http –permanent
sudo firewall-cmd --add-port=80/tcp --permanent
重启防火墙
firewall-cmd –reload
5,配置
nginx.conf配置文件
http块是经常配置的代码块
server {
listen 80; //监听80端口
server_name 112.125.89.59;
#charset koi8-r;
#access_log logs/host.access.log main;
location / { //代理静态资源
#proxy_pass http://myserver;
#root html;
root /root/blog;
index index.html index.html;
}
配置完成后重新加载
在/usr/local/nginx/sbin 目录下执行 ./nginx -s reload
至此成功搭建静态节点