目录
1.参考资料
2. 安装 Nginx
2.1 Ubuntu 安装步骤
2.1.1 解压安装包
解压命令:
tar -zxvf nginx-1.20.2.tar.gz
2.1.2 配置选项
先安装依赖包
安装命令:
# 查看某个包是否安装
dpkg -l | grep zlib
# 解决安装 openssl
sudo apt-get install openssl libssl-dev
# 解决安装 PRCE
sudo apt-get install libpcre3 libpcre3-dev
# 解决安装 zlib
sudo apt-get install zlib1g-dev
执行 configure 命令生成 makefile 文件:
cd /home/public/Soft/nginx-1.20.2
./configure --sbin-path=/home/public/Soft/nginx-1.20.2 --conf-path=/home/public/Soft/nginx-1.20.2/conf/nginx.conf --pid-path=/home/public/Soft/nginx-1.20.2/nginx.pid --with-http_ssl_module
成功:
Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ using system zlib library
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/home/public/Soft/nginx-1.20.2"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/home/public/Soft/nginx-1.20.2/conf"
nginx configuration file: "/home/public/Soft/nginx-1.20.2/conf/nginx.conf"
nginx pid file: "/home/public/Soft/nginx-1.20.2/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"
在 安装目录下生成了 makefile 文件:
记录一下执行 configuration 时报错:
./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.
2.1.3 make 命令编译
根据生成的Makefile文件,生成 nginx 启动文件:
cd /home/public/Soft/nginx-1.20.2
make
sudo make install
2.2.4 启动 nginx
启动 nginx 命令:
cd /home/public/Soft/nginx-1.20.2
# 启动nginx
sudo ./nginx
报错 :
nginx: [alert] could not open error log file: open() "/usr/local/nginx/logs/error.log" failed (2: No such file or directory)
2021/11/24 09:46:28 [emerg] 30584#0: open() "/usr/local/nginx/logs/error.log" failed (2: No such file or directory)
创建错误日志路径:
sudo mkdir -p /usr/local/nginx/logs/
再次启动:
cd /home/public/Soft/nginx-1.20.2
# 启动nginx
sudo ./nginx
2.1.5 验证 nginx
浏览器访问 :http://localhost:80/
到此,nginx 启动成功。
2.2 CentOS7 安装步骤
2.2.1 解压安装包
解压命令:
tar -zxvf nginx-1.18.0.tar.gz
2.2.2 安装依赖
# 解决安装 openssl
yum install openssl-devel.x86_64 libssl-dev
# 解决安装 PRCE
yum install pcre.x86_64 pcre-devel.x86_64
# 解决安装 zlib
yum install zlib1g-dev
./configure --sbin-path=/opt/nginx/nginx-1.18.0 --conf-path=/opt/nginx/nginx-1.18.0/conf/nginx.conf --pid-path=/opt/nginx/nginx-1.18.0/nginx.pid --with-http_ssl_module
控制台输出:
Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ using system zlib library
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/opt/nginx/nginx-1.18.0"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/opt/nginx/nginx-1.18.0/conf"
nginx configuration file: "/opt/nginx/nginx-1.18.0/conf/nginx.conf"
nginx pid file: "/opt/nginx/nginx-1.18.0/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"
2.2.3 make 命令编译
cd /opt/nginx/nginx-1.18.0
make
2.2.4 make install 命令安装
但是报错了:
尝试启动:
mkdir -p /usr/local/nginx/logs/
./nginx
没有报错,说明 Nginx 安装成功了。
2.3 Windows 安装步骤
2.3.1 下载
2.3.2 解压
2.3.3 启动
打开 CMD ,切换到解压目录下,输入“nginx.exe”,回车
CMD窗口未输出异常信息,证明启动成功。
2.3.4 验证
浏览器输入:http://localhost:80/ 出现以下界面则证明安装成功:
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.
Thank you for using nginx.
本文来自博客园,作者:不安分的黑娃,转载请注明原文链接:https://www.cnblogs.com/lihw-study/p/16756242.html