nginx安装:
环境:CentOS7
Nginx版本:
下载地址:nginx-1.24.0
百度网盘地址:链接:https://pan.baidu.com/s/1fHMyi068Cm8_r7pP9zZeQQ?pwd=ng12 提取码:ng12
命令下载:wget https://www.nginx.org/download/nginx-1.24.0.tar.gz
安装:
解压:tar -zxvf nginx-1.24.0.tar.gz
进入解压目录:cd nginx-1.24.0/
执行环境配置 制定安装目录:./configure --prefix=/usr/local/nginx(安装目录绝对路径)
安装模块示例:./configure --prefix=/usr/local/nginx --with-http_ssl_module(https模块)
问题:
./configure: error: C compiler cc is not found:缺少gcc yum -y install gcc
./configure: error: the HTTP rewrite module requires the PCRE library.: 缺失 PCRE库 yum -y install pcre-devel
./configure: error: SSL modules require the OpenSSL library. 缺失 OpenSSL yum -y install OpenSSL openssl-devel
配置成功:
编译及安装:make && make install
启动命令:
进入安装目录:cd /usr/local/nginx(prefix配置目录)
启动:./nginx
停止:./nginx -s stop
重启:./nginx -s reload
启动指定配置文件:./nginx -c /usr/local/nginx/conf/nginx.conf
配置服务文件
cd /lib/systemd/system
新增文件 vim nginx.service
启动nginx: systemctl start nginx.service
查看状态:systemctl status nginx.service
停止nginx: systemctl stop nginx.service
重启nginx:systemctl reload nginx.service
异常:
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
执行:journalctl -xe 查看原因
例:端口被占用;用原始命令停止服务后重启执行
开机自启添加:systemctl enable nginx.service
开机自启关闭:systemctl disable nginx.service
关闭防火墙:systemctl stop firewalld.service
开放端口:firewall-cmd --zone=public --add-port=80/tcp –permanent
查询本机ip:ifconfig
访问nginx:(默认80端口)