Ubuntu虚拟机:Nginx安装的小坑:1.依赖包 2.版本问题 3.80端口占用

1.E: Unable to locate package PCRE

解决方案:

安装 PCRE 库

  1. 更新包列表:
sudo apt-get update
  1. 安装 PCRE 库及其开发头文件:
sudo apt-get install libpcre3 libpcre3-dev

安装其他依赖项

为了确保 Nginx 编译顺利,还需要安装其他依赖项:

sudo apt-get install zlib1g zlib1g-dev sudo apt-get install libssl-dev

重新编译 Nginx

完成依赖项安装后,重新配置并编译 Nginx:

  1. 进入 Nginx 源码目录:
cd ~/Package/nginx-1.12.2
  1. 配置编译选项:
./configure
  1. 编译和安装 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比较好

官网下下地址:nginx: download

比较直接干脆的的方法: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端口 即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值