目录

工欲善其事

实践出真知

活跃标签: linux java mysql 待分类 js springboot win10 电路 vue macOS nginx esp32 windows git docker idea maven esp8266 python Arduino

存档:

X

[ Nginx ] 在80端口被占用后可起不来的原因

今天想启动 香橙派🍊上的Nginx传点文件,一直在报80端口被占用的错。因为80端口给博客用了,并且也把Nginx的配置改到了别的端口上为什么还是报错!

image.png

找问题

1、一开始怀疑配置的问题,检查了好多遍确定没问题 ✅

2、找搜索引擎 ... 没找到什么有用的答案,大部份是告诉你杀掉 80 的进程!(我TM用你告诉我??)另一部分就在狗扯 ❌

3、再回头看配置文件,发现了可疑的导入 ✌🏻

image.png

看这个配置文件/etc/nginx/nginx.conf 发现有三处引入,2是我配置的文件夹,1和3是做什么的?

1、看名字好像是模块什么的,打开一个配置文件看了下应该是某种功能的组建

load_module modules/ngx_stream_module.so;

2、翻译过来是启用站点 那应该就是它啦!内容如下:

##
# 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;
#	}
#}

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.

通常情况下,网站管理员会将此文件的链接从 sites-enabled 中删除,并将其作为 sites-available 中其他文件的参考,nginx packaging team 将持续对此文件进行更新。

也就是说,文件夹下的** default 为网站配置文件的参考,由于在 **nginx 更新时,default 会一同被更新以展示配置文件的变化,所以在配置网站时,不应该直接修改此文件,需要复制为新文件,再进行修改。

而** sites-available 则是用于存放网站的配置文件,意为可用的网站列表,用于在需要时链接到 **sites-enabled 中作为需要启用的网站。

sites-enabled 文件夹


sites-enabled 中则只拥有** sites-available 文件夹下 **default 的软链接,结合前面得出:

  • sites-enabled 下的文件,会作为** **nginx.conf 的一部分加载
  • sites-enabled 下的用于存放** **sites-available 中文件的软连接

sites-enabled 意为已开启的网站,将** sites-available 中的配置文件链接到此处,以使配置文件被 **nginx 加载。

总结

删掉之后启动成功~

image.png


标题:[ Nginx ] 在80端口被占用后可起不来的原因
作者:llilei
地址:http://solo.llilei.work/articles/2023/03/04/1677906515361.html