ubuntu中出现 nginx 启动报错:Job for nginx.service failed because the control process exited with error code

本文详细介绍了如何解决Linux系统上Nginx与Apache因端口80冲突而导致的服务启动失败问题,提供了检查端口占用状态、终止Apache进程及修改Apache配置文件的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

当你安装完nginx并 启动报错:Job for nginx.service failed because the control process exited with error code这样的错误的时候,我这边出现的问题是端口冲突导致的,因为我linux中也安装了apache2,然后apache2已经启动所以当你启动nginx的时候就会出现错误问题。

当你安装完nginx的时候,它启用的端口是80;

当你不确定是否是端口冲突,你首先去查看apache2是否启动,然后查看apache2端口是多少。

ps -aux | grep apache2

ps -ef | grep apache2

找到进程id(上面两种方法都可以查询)

然后使用

netstat -nap | grep 进程id

如果查询出来的端口号确实是80端口

解决方法有

1、kill apache2

首先你要去查找你的apache2的进程id

kill -9   进程id

2、修改apache2的端口号,这样可以避免两个同时开启的时候出现错误问题

step1:修改监听端口以及主机端口为81

打开目录/etc/apache2/ports.conf文件,将端口的80改为81

命令sudo vi /etc/apache2/ports.conf

step2: 只要修改virtualHost的端口即可

在ports.conf文件中看到了注释,/etc/apache2/sites-enabled/000-default文件,打开文件后把<VirtualHost *:80>修改成81

命令sudo vi /etc/apache2/sites-enabled/000-default

step3:重启apache2

命令service apache2 restart

查看端口号lsof -i:80

 

myenv) root@lavm-1jdi3tufk3:/etc/nginx/sites-available# sudo apt install nginx -y Reading package lists... Done Building dependency tree... Done Reading state information... Done nginx is already the newest version (1.18.0-6ubuntu14.6). 0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded. 2 not fully installed or removed. After this operation, 0 B of additional disk space will be used. Setting up nginx-core (1.18.0-6ubuntu14.6) ... Progress: [ 0%] [...........................................................................................................................................................................................] Job for nginx.service failed because the control process exited with error code..............................................................................................................................] See "systemctl status nginx.service" and "journalctl -xeu nginx.service" for details. invoke-rc.d: initscript nginx, action "start" failed. × nginx.service - A high performance web server and a reverse proxy server Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Sun 2025-07-13 14:27:15 CST; 10ms ago Docs: man:nginx(8) Process: 686182 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE) CPU: 12ms Jul 13 14:27:15 lavm-1jdi3tufk3 systemd[1]: Starting A high performance web server and a reverse proxy server... Jul 13 14:27:15 lavm-1jdi3tufk3 nginx[686182]: nginx: [emerg] invalid number of arguments in "proxy_set_header" directive in /etc/nginx/sites-enabled/flaskapp:32 Jul 13 14:27:15 lavm-1jdi3tufk3 nginx[686182]: nginx: configuration file /etc/nginx/nginx.conf test failed Jul 13 14:27:15 lavm-1jdi3tufk3 systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE Jul 13 14:27:15 lavm-1jdi3tufk3 systemd[1]: nginx.service: Failed with result 'exit-code'. Jul 13 14:27:15 lavm-1jdi3tufk3 systemd[1]: Failed to start A high performance web server and a reverse proxy server. dpkg: error processing package nginx-core (--configure): installed nginx-core package post-installation script subprocess returned error exit status 1 dpkg: dependency problems prevent configuration of nginx: nginx depends on nginx-core (<< 1.18.0-6ubuntu14.6.1~) | nginx-full (<< 1.18.0-6ubuntu14.6.1~) | nginx-light (<< 1.18.0-6ubuntu14.6.1~) | nginx-extras (<< 1.18.0-6ubuntu14.6.1~); however: Package nginx-core is not configured yet. Package nginx-full is not installed. Package nginx-light is not installed. Package nginx-extras is not installed. nginx depends on nginx-core (>= 1.18.0-6ubuntu14.6) | nginx-full (>= 1.18.0-6ubuntu14.6) | nginx-light (>= 1.18.0-6ubuntu14.6) | nginx-extras (>= 1.18.0-6ubuntu14.6); however: Package nginx-core is not configured yet. Package nginx-full is not installed. Package nginx-light is not installed. Package nginx-extras is not installed. dpkg: error processing package nginx (--configure): dependency problems - leaving unconfigured No apport report written because the error message indicates its a followup error from a previous failure. Errors were encountered while processing: nginx-core nginx needrestart is being skipped since dpkg has failed E: Sub-process /usr/bin/dpkg returned an error code (1)
最新发布
07-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值