Nginx启动显示80端口占用问题的解决方案

 更新时间:2024年04月29日 11:24:52   作者:SarPro  
这篇文章主要介绍了Nginx启动显示80端口占用问题的解决方案,文中通过代码示例和图文讲解的非常详细,对大家解决问题有一定的帮助,需要的朋友可以参考下

1. 问题描述

在启动nginx服务的时候显示内容如下:

sudo systemctl status nginx

问题出现原因:

根据日志显示,Nginx 服务启动失败,主要原因是无法绑定到端口 80。这通常是由于该端口已被

其他进程占用而导致的。

2. 解决方案

要解决此问题,可以执行以下步骤:

确认端口 80 是否被其他进程占用。可以使用以下命令检查:

sudo netstat -tuln | grep :80

该命令会列出正在监听端口 80 的进程。如果有其他进程在使用该端口,显示如下:

打开配置文件:可以将80端口【默认端口】修改为 8080 端口【当然也可以是其他的,不过要记得去防火墙添加规则(即添加端口)】

比如我添加的是 8080 端口,则添加规则如下(红框内容):

可以使用以下命令打开配置文件:

sudo nano /etc/nginx/sites-available/*

我的配置文件内容如下【版本不同当然配置文件不同】:

##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##
# Default server configuration
#
server {
	listen 80 default_server;
	listen [::]:80 default_server;
	# SSL configuration
	#
	# listen 443 ssl default_server;
	# listen [::]:443 ssl default_server;
	#
	# Note: You should disable gzip for SSL traffic.
	# See: https://bugs.debian.org/773332
	#
	# Read up on ssl_ciphers to ensure a secure configuration.
	# See: https://bugs.debian.org/765782
	#
	# Self signed certs generated by the ssl-cert package
	# Don't use them in a production server!
	#
	# include snippets/snakeoil.conf;
 
	root /var/www/html;
 
	# Add index.php to the list if you are using PHP
	index index.html index.htm index.nginx-debian.html;
 
	server_name _;
 
	location / {
		# First attempt to serve request as file, then
		# as directory, then fall back to displaying a 404.
		try_files $uri $uri/ =404;
	}
 
	# pass PHP scripts to FastCGI server
	#
	#location ~ \.php$ {
	#	include snippets/fastcgi-php.conf;
	#
	#	# With php-fpm (or other unix sockets):
	#	fastcgi_pass unix:/run/php/php7.4-fpm.sock;
	#	# With php-cgi (or other tcp sockets):
	#	fastcgi_pass 127.0.0.1:9000;
	#}
 
	# deny access to .htaccess files, if Apache's document root
	# concurs with nginx's one
	#
	#location ~ /\.ht {
	#	deny all;
	#}
}
 
 
# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#	listen 80;
#	listen [::]:80;
#
#	server_name example.com;
#
#	root /var/www/example.com;
#	index index.html;
#
#	location / {
#		try_files $uri $uri/ =404;
#	}
#}

将里面的代码模块

server {
    listen 80 default_server;
    listen [::]:80 default_server;

修改成

server {
    listen 8080 default_server;
    listen [::]:8080 default_server;

完成修改!【如果其他地方还有 80 的修改成 8080 即可】。

启动Nginx服务

sudo systemctl start nginx

设置Nginx服务自启动:

sudo systemctl enable nginx

验证Nginx是否运行:

sudo systemctl status nginx

如果一切正常,输出应该是“Active: active (running)”或者类似的信息。

以上就是Nginx启动显示80端口占用问题的解决方案的详细内容,更多关于Nginx 80端口占用的资料请关注脚本之家其它相关文章!

相关文章

  • 详解如何部署H5游戏到nginx服务器

    详解如何部署H5游戏到nginx服务器

    这篇文章主要介绍了详解如何部署H5游戏到nginx服务器,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-05-05
  • nginx部署vue页面白屏或刷新404问题解决

    nginx部署vue页面白屏或刷新404问题解决

    最近部署vue项目后发现刷新页面会404,本文就来介绍一下nginx部署vue页面白屏或刷新404问题解决,具有一定的参考价值,感兴趣的可以了解一下
    2023-10-10
  • 永中文档在线转换预览基于nginx配置部署方案

    永中文档在线转换预览基于nginx配置部署方案

    这篇文章主要为大家介绍了永中文档在线转换预览基于nginx配置部署方案的实现,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2022-06-06
  • win10上安装nginx的方法步骤

    win10上安装nginx的方法步骤

    这篇文章主要介绍了win10上安装nginx的方法步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2019-10-10
  • PHP开发框架kohana3.3.1在nginx下的伪静态设置例子

    PHP开发框架kohana3.3.1在nginx下的伪静态设置例子

    这篇文章主要介绍了PHP开发框架kohana3.3.1在nginx下的伪静态设置例子,kohana曾经是codeigniter框架的衍生版,后来发展成另一个独立的PHP5开发框架,需要的朋友可以参考下
    2014-07-07
  • Nginx报错104:Connection reset by peer问题的解决及分析

    Nginx报错104:Connection reset by peer问题的解决及分析

    最近恰好又遇到这了个错误,为了加深记忆,所以记录下我遇到这个错误的主要原因,下面这篇文章主要给大家介绍了关于Nginx报错104:Connection reset by peer问题的解决及分析的相关资料,需要的朋友可以参考下
    2022-07-07
  • 详解如何通过nginx进行服务的负载均衡

    详解如何通过nginx进行服务的负载均衡

    负载均衡器可以将用户请求根据对应的负载均衡算法分发到应用集群中的一台服务器进行处理,本文主要为大家详细介绍了如何通过nginx进行服务的负载均衡,需要的可以参考下
    2023-11-11
  • Docker Nginx容器和Tomcat容器实现负载均衡与动静分离操作

    Docker Nginx容器和Tomcat容器实现负载均衡与动静分离操作

    这篇文章主要介绍了Docker Nginx容器和Tomcat容器实现负载均衡与动静分离操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2020-11-11
  • 服务器重启后宝塔界面打开显示404 nginx的解决方法

    服务器重启后宝塔界面打开显示404 nginx的解决方法

    在阿里云服务器搭建宝塔界面,服务器重启之后打开宝塔显示404 not found nginx,本文给大家介绍了服务器重启后宝塔界面打开显示404 nginx的解决方法,需要的朋友可以参考下
    2024-02-02
  • Nginx为Tomcat服务器作反向代理的配置教程

    Nginx为Tomcat服务器作反向代理的配置教程

    这篇文章主要介绍了Nginx为Tomcat服务器作反向代理的配置教程,文中以Windows系统为环境来演示驱动JSP程序的示例,需要的朋友可以参考下
    2016-03-03

最新评论