1.E: Unable to locate package PCRE
解决方案:
安装 PCRE 库
- 更新包列表:
sudo apt-get update
- 安装 PCRE 库及其开发头文件:
sudo apt-get install libpcre3 libpcre3-dev
安装其他依赖项
为了确保 Nginx 编译顺利,还需要安装其他依赖项:
sudo apt-get install zlib1g zlib1g-dev sudo apt-get install libssl-dev
重新编译 Nginx
完成依赖项安装后,重新配置并编译 Nginx:
- 进入 Nginx 源码目录:
cd ~/Package/nginx-1.12.2
- 配置编译选项:
./configure
- 编译和安装 Nginx:
make
sudo make install
问题2.src/os/unix/ngx_user.c: In function ‘ngx_libc_crypt’: src/os/unix/ngx_user.c:36:7: error: ‘struct crypt_data’ has no member named ‘current_salt’ 36 | cd.current_salt[0] = ~salt[0]; | ^ make[1]: *** [objs/Makefile:777: objs/src/os/unix/ngx_user.o] Error 1
解决方案:源码的问题,基本上都是版本的问题,更新一个较新的ngin比较好
比较直接干脆的的方法:sudo apt-get install nginx
直接安装 Nginx 包(可选)
如果不需要自定义编译,可以直接使用 APT 安装 Nginx,这样会自动处理所有依赖项:
sudo apt-get install nginx
安装完成后,使用以下命令启动和管理 Nginx:
sudo systemctl start nginx
sudo systemctl enable nginx
通过这些步骤,你应该能够正确安装 PCRE 库及其依赖项,并成功编译和安装 Nginx。
问题3:启动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()
解决方法1:
1.查看是不是已经启动了
ps aux | grep nginx
2.查看传统的80(Nginx默认的端口)
netstat -ntlp|grep 80
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp6 0 0 :::80 :::* LISTEN
查看到底什么进程占用了这个端口号
sudo lsof -i :80
[sudo] password for xxx:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
apache2 2221 root 4u IPv6 112699 0t0 TCP *:http (LISTEN)
apache2 6095 www-data 4u IPv6 112699 0t0 TCP *:http (LISTEN)
apache2 6096 www-data 4u IPv6 112699 0t0 TCP *:http (LISTEN)
问题原因:apache2作为http服务器占用了80端口,Ubuntu系统导致的,默认80端口给http服务,但是Windows正常的http服务都是8080端口的。所以我们要修改端口,尽量修改Nginx的端口。
解决方法:直接修改默认端口号
#apt insatll 自动编译的
sudo vim /etc/nginx/nginx/sites-available/default
#如果是下载安装包编译的,则
sudo vim /usr/local/nginx//sites-available/default
直接修改成8080端口 即可