nginx安装步骤
1. 上传Nginx安装包
上传到opt目录失败,没有权限。上传到/home/nginx 目录。
2. 解压安装包
tar -zxvf nginx-1.14.2.tar.gz
3. 编译
权限原因,指定安装位置为 /home/nginx/nginx
运行如下编译命令。
./configure --prefix=/home/nginx/nginx
有错误提示,环境不全
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
yum -y install pcre-devel openssl openssl-devel
内网无网络,外部下载pcre-8.37.tar.gz 上传至 /home/nginx,其余依赖一并如此安装。
解压并编译安装
tar -zxvf pcre-8.37.tar.gz
cd pcre-8.37/
./configure
#切换root用户,否则没有权限
make&&make install
依赖安装完成后重新执行如下命令编译nginx,指定目录/home/nginx/nginx-server
./configure --prefix=/home/nginx/nginx-server
Configuration summary
+ using system PCRE library
+ OpenSSL library is not used
+ using system zlib library
nginx path prefix: "/home/nginx/nginx-server"
nginx binary file: "/home/nginx/nginx-server/sbin/nginx"
nginx modules path: "/home/nginx/nginx-server/modules"
nginx configuration prefix: "/home/nginx/nginx-server/conf"
nginx configuration file: "/home/nginx/nginx-server/conf/nginx.conf"
nginx pid file: "/home/nginx/nginx-server/logs/nginx.pid"
nginx error log file: "/home/nginx/nginx-server/logs/error.log"
nginx http access log file: "/home/nginx/nginx-server/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp
4. 安装
make&&make install
安装完毕后启动报错。
nginx用户无法使用80端口。切换为root用户启动。
nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)
5. 启动
./sbin/nginx
启动成功后,浏览器访问,打开失败。
查看80端口,防火墙未打开。
firewall-cmd --query-port=80/tcp
false
设置临时打开
firewall-cmd --zone=public --add-port=80/tcp
#firewall-cmd --zone=public --add-port=80/tcp --permanent
再次访问浏览器,显示403。
修改配置文件,变更启动用户 为root
user root
重新刷新配置,访问正常。
文档信息
- 本文作者:chayedankase
- 本文链接:https://chayedankase.github.io/2020/04/25/nginx%E5%AE%89%E8%A3%85%E6%AD%A5%E9%AA%A4/
- 版权声明:自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)