下载所需依赖
本文使用系统为ubuntu
nginx官网:https://nginx.org/en/download.html
centos
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
ubuntu
源码安装
安装OpenSSL
tar -zxvf openssl-3.0.0-alpha6.tar.gz
cd openssl-3.0.0-alpha6
./config
make
make install
安装zlib
tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure
make
make install
安装pcre
tar -zxvf pcre-8.44.tar.gz
cd pcre-8.44
./configure
make
make install
安装nginx
tar -zxvf nginx-1.18.0.tar.gz
cd nginx-1.18.0
./configure
make
make install
nginx安装位置:/usr/local/nginx
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/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"
安装结束之后,检测是否安装成功:
启动
进入安装目录,执行nginx二进制文件:
但是发现,启动失败,原因是缺少libpcre.so.1这个库
具体查看nginx所需要的库:
其他的库都在"/lib/x86_64-linux-gnu//"目录中,那么可以进入该目录,查看是否有所缺库:
发现果然存在缺的这个库,那么接下来创建软连接就完事了:
在重新启动nginx之前,去看一下配置文件( /usr/local/nginx/conf/nginx.conf ):
nginx的默认端口是80,这里我把它改成了8099。
重新启动,然后在浏览器中访问服务器ip:
出现欢迎页,nginx安装完成!