nginx启动提示98address已被占用(CentOS 7 用户怎样安装 LNMP)

本文目录
- CentOS 7 用户怎样安装 LNMP
- 在windows上启动nginx 出现了错误
- 解决socket.error: [Errno 98] Address already in use问题
- linux启动apache命令报错(98)Address already in use: make_sock: could not bind to address [::]:80
- nginx 服务器 有一个 虚拟挂不上去 启动是下面的提示
- nginx无法启动的问题
- nginx启动报错!~~帮忙看看
- nginx 修改端口没用
- linux nginx的端口问题,我要把默认的80端口改成8088,报错
CentOS 7 用户怎样安装 LNMP
1 先说一下
本文使用的主机名称: server1.example.com 和IP地址: 192.168.1.105。这些可能与你的计算机有所不同,注意进行修改。
2 使用外部仓库
Nginx不是从官方CentOS库安装,我们从 nginx 项目安装库安装,修改源:
vi /etc/yum.repos.d/nginx.repo
修改为:
name=nginx repo
***隐藏网址***
gpgcheck=0
enabled=1
3 安装 MySQL
我们先安装MariaDB。一个免费的MySQL 分支。运行此命令:
yum install mariadb mariadb-server net-tools
然后我们创建MySQL系统启动链接(所以MySQL的自动启动时,系统启动)启动MySQL服务器:
systemctl enable mariadb.service
systemctl start mariadb.service
现在检查网络启用。运行
netstat -tap | grep mysql
它应该显示出这样的内容:
# netstat -tap | grep mysql
tcp 0 0 0.0.0.0:mysql 0.0.0.0:* LISTEN 10623/mysqld
运行
mysql_secure_installation
为用户设置根口令(否则,任何人都可以访问你的MySQL数据库!):
# mysql_secure_installation
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we’ll need the current
password for the root user. If you’ve just installed MariaDB, and
you haven’t set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on…
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? 《– 回车
New password: 《– 输入ROOT密码
Re-enter new password: 《– 再输入一次ROOT密码
Password updated successfully!
Reloading privilege tables..
… Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? 《– 回车
… Success!
Normally, root should only be allowed to connect from ‘localhost’. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? 《– 回车
… Success!
By default, MariaDB comes with a database named ‘test’ that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? 《– 回车
- Dropping test database…
… Success!
- Removing privileges on test database…
… Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? 《– 回车
… Success!
Cleaning up…
All done! If you’ve completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
#
# mysql_secure_installation
4 安装 Nginx
Nginx可以作为一个包从nginx.org安装,运行:
yum install nginx
然后我们创建的系统启动nginx的链接和启动它:
systemctl enable nginx.service
systemctl start nginx.service
有时,你会得到一个错误,如80端口已在使用中,错误消息会是这样的
# service nginx start
Starting nginx: nginx: bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: still could not bind()
#
这就意味着有时在运行Apache服务。停止服务,进一步启动服务nginx如下
***隐藏网址***
***隐藏网址***
***隐藏网址***
systemctl enable nginx.service
systemctl start nginx.service
开放的HTTP和HTTPS防火墙中的端口
***隐藏网址***
***隐藏网址***
firewall-cmd –reload
输出的shell结果将看起来像这样:
***隐藏网址***
success
***隐藏网址***
success
# firewall-cmd –reload
success
#
在你的Web服务器的IP地址或主机名称输入到浏览器(如HTTP:/ /192.168.1.105),你应该看到nginx的欢迎页面。
5 安装 PHP5
我们可以通过PHP-FPM使nginx的PHP5工作(PHP-FPM(FastCGI进程管理器)是一种替代PHP FastCGI执行一些额外的功能,支持任何规模大小,尤其是繁忙的站点很有用)。我们可以安装php-fpmtogether用PHP-CLI和一些PHP5的模块,如PHP,MySQL,你需要的,如果你想使用MySQL的PHP命令如下:
yum install php-fpm php-cli php-mysql php-gd php-ldap php-odbc php-pdo php-pecl-memcache php-pear php-mbstring php-xml php-xmlrpc php-mbstring php-snmp php-soap
APC是一个自由和开放的PHP操作码来缓存和优化PHP的中间代码。它类似于其他PHP操作码cachers,如eAccelerator和XCache。强烈建议有���些安装,以加快您的PHP页面。
我会从PHP PECL库中安装的APC。 PECL要求CentOS开发工具beinstalled编译APC包。
yum install php-devel
yum groupinstall ‘Development Tools’
安装 APC
pecl install apc
# pecl install apc
downloading APC-3.1.13.tgz …
Starting to download APC-3.1.13.tgz (171,591 bytes)
……………..done: 171,591 bytes
55 source files, building
running: phpize
Configuring for:
PHP Api Version: 20100412
Zend Module Api No: 20100525
Zend Extension Api No: 220100525
Enable internal debugging in APC : 《– 回车
Enable per request file info about files used from the APC cache : 《– 回车
Enable spin locks (EXPERIMENTAL) : 《– 回车
Enable memory protection (EXPERIMENTAL) : 《– 回车
Enable pthread mutexes (default) : 《–回车
Enable pthread read/write locks (EXPERIMENTAL) : 《– 回车
building in /var/tmp/pear-build-rootVrjsuq/APC-3.1.13
……
然后打开 /etc/php.ini 并设置 cgi.fix_pathinfo=0:
vi /etc/php.ini
; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI. PHP’s
; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok
; what PATH_INFO is. For more information on PATH_INFO, see the cgi specs. Setting
; this to 1 will cause PHP CGI to fix its paths to conform to the spec. A setting
; of zero causes PHP to behave as before. Default is 1. You should fix your scripts
; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
***隐藏网址***
cgi.fix_pathinfo=0
并添加行:
extension=apc.so
在 /etc/php.ini 文件后面。
除此之外,为了避免这样的时区的错误:
PHP Warning: phpinfo(): It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘Europe/Berlin’ for ‘CEST/2.0/DST’ instead in /usr/share/nginx/html/info.php on line 2
… in /var/log/php-fpm/www-error.log 当你在浏览器中调用一个PHP脚本,你应该设置 date.timezone in /etc/php.ini:
; Defines the default timezone used by the date functions
***隐藏网址***
date.timezone = "Europe/Berlin"
您可以通过运行正确的时区支持您的系统:
cat /etc/sysconfig/clock
# cat /etc/sysconfig/clock
ZONE=”Europe/Berlin”
#
接下来,创建系统启动链接的PHP-FPM并启动它:
systemctl enable php-fpm.service
systemctl start php-fpm.service
PHP-FPM是一个守护进程(使用init脚本/etc/init.d/php-fpm) 运行在端口9000的FastCGI服务器。
在windows上启动nginx 出现了错误
可能是端口占用问题,win10系统默认占用了80端口。
经过网络查询,发现网上的提供的多种方式,单纯使用,并不能解决问题,经实践后,解决方式为3步:
***隐藏网址***
***隐藏网址***
***隐藏网址******隐藏网址***
没有任何提示,重新出现输入提示,说明已经成功,如果有提示,请按提示进行修改。
然后重启电脑,输入netstat -ano | find "0.0.0.0:80"命令进行验证。如果没有任务输出,说明成功,如果还是有80端口相关信息输出,说明失败。可以再尝试其他方式。
解决socket.error: [Errno 98] Address already in use问题
刚刚开始使用flask框架写了两个小程序。然后我先访问了第一个“Hello,Web”的小程序,运行通过,然后想看看第二个inputname的程序是不是写对,但是linux报错:
socket.error: Address already in use
大概意思就是地址被占用。因为socket默认是不支持地址复用的。为什么程序跑完了端口还是被占用着?这个问题就要TCP连接的“四次挥手”。
我们可能都有听过TCP/IP中“三次握手,四次挥手”,前者我们可能会更加了解一点,后者就不知道是什么样子。我也是T_T,所以我决定弄懂它。
在TCP/IP终止连接的四次握手中,当最后的ACK回复发出后,有个 2MSL 的时间等待,MSL指一个片段在网络中最大的存活时间,这个时间一般是30秒,所以基本上过60秒后就可以重新连接!
为什么要等待2MSL?是因为在最后发出ACK回复后,发送方不能确认ACK是否被另一端正常收到,如果另一端没有收到ACK回复的话,将会在1MSL后再次发送FIN片段。所以说发送方等待2MSL时间,也就是刚好它发ACK回复和对方发送FIN片段的时间,如果此时间内都没有再次收到FIN片段的话,发送方就假设对方已经正常接收到了ACK回复,此时它就会正常关闭连接!
以上就解释了为什么会出现跑另一个程序时会出现地址占用的情况。
接下去就是解决方案:
如果并发连接请求过多的时候,即短时间内连接请求很多,系统自动释放已占用端口的时间还没有到,又有连接请求(可用的端口已经被用完),所以还会出现 Address already in use错误提示),就会产生大量的TIME_WAIT状态的连接。这种情况下就有必要调整下linux的TCP/IP内核参数,让系统更快的释放TIME_WAIT连接。对于并发连接量大的情况我们需要这样设置:
linux启动apache命令报错(98)Address already in use: make_sock: could not bind to address [::]:80
***隐藏网址***
解决办法:
root用户登录,用./apachectl stop停掉apache或kill -9 pid
chown -R cib:cib /apache 把整个apache的目录重新赋权限给cib用户
***隐藏网址***
切换到cib用户,用./apachectl start启动apache就可以了
***隐藏网址***
nginx 服务器 有一个 虚拟挂不上去 启动是下面的提示
错误提示显示:Address already in use. 也就是说nginx需要监听的80端口已经被其它的服务占用了。导致nginx启动的时候不能监听80端口。
原因有两个:
(1)确实有其他服务占用80端口;
(2)已经有一个nginx在运行了。
可以使用lsof命令查看80端口的使用情况。
lsof -i:80
nginx本身应该是没有问题的。
nginx无法启动的问题
第一个办法是更改系统的默认配置。打开注册表regedit,HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\HTTP,在右边找到Start这一项,将其改为0,重启。
第二种做法就是更改Nginx的默认端口号,比如我们改成8088。然后再启动Nginx,打开浏览器输入localhost:8088就可以看到欢迎页面了。
简介:
Nginx ("engine x") 是一个高性能的HTTP和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 服务器。 Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,第一个公开版本0.1.0发布于2004年10月4日。其将源代码以类BSD许可证的形式发布,因它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名。2011年6月1日,nginx 1.0.4发布。
Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行。由俄罗斯的程序设计师Igor Sysoev所开发,供俄国大型的入口网站及搜索引擎Rambler(俄文:Рамблер)使用。其特点是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页服务器中表现较好,中国大陆使用nginx网站用户有:百度、新浪、网易、腾讯、 淘宝等。
特性:
1.处理静态文件,索引文件以及自动索引;打开文件描述符缓冲.
2.无缓存的反向代理加速,简单的负载均衡和容错.
3.FastCGI,简单的负载均衡和容错.
4.模块化的结构。包括gzipping, byte ranges, chunked responses, 以及 SSI-filter等filter。如果由FastCGI或其它代理服务器处理单页中存在的多个SSI,则这项处理可以并行运行,而不需要相互等待。
5.支持SSL 和 TLS SNI.
nginx启动报错!~~帮忙看看
找到原因了,配置文件里面的域名写重复了 导致80端口冲突
重新启动服务器发现报nginx: open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)错误。
解决方法:
# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
使用nginx -c的参数指定nginx.conf文件的位置
# cd logs/
# ll
总用量 12
-rw-r--r-- 1 root root 1246 12月 9 18:10 access.log
-rw-r--r-- 1 root root 516 12月 10 15:39 error.log
-rw-r--r-- 1 root root 5 12月 10 15:38 nginx.pid
nginx 修改端口没用
从左边的图片看来 应该是80端口被占用了,所以无法启动nginx,可以使用lsof -i:80查看端口是否被使用。
从右边的图片看,你配置的端口是8083,你将localhost改为实际的ip,在试试
如果还是提示80端口被占用,可以使用 service nginx start
linux nginx的端口问题,我要把默认的80端口改成8088,报错
ps -ef | grep nginx 查看进程号
kill -9 进程号 杀掉进程
/usr/local/nginx/sbin/nginx 重启服务
看看这个端口被什么进程占用
然后杀死进程
可以查看下80端口被哪个程序占用,把占用端口的程序关闭即可。
查看端口占用命令

更多文章:
maven配置文件的类型(配置一份需要junit和jdbc依赖的Maven项目基本配置文件pom.xml)
2025年6月3日 22:15
rustdesk自建服务器教程(方舟:生存进化-搭建服务器联机教程)
2026年8月30日 15:15
linux环境变量添加(linux系统下怎么修改path环境变量)
2025年6月24日 08:45
svc静止无功补偿(请问既然SVC是静止型动态无功补偿,那么非静止型的动态无功补偿是什么原理呢)
2025年7月12日 07:30
oracle客户端环境变量配置(最近在win7下安装了Oracle 11g,安装完成后需要设置哪些环境变量呢)
2026年9月21日 06:30
exploration是什么意思(expedition和exploration的区别,用法)
2025年11月19日 02:45
手机上的个人主页怎么找(怎么进入自己的手机淘宝详细资料/个人主页)
2026年3月26日 18:45
webviewjavascriptbridge(安卓webview跳转后bridge不生效)
2025年11月30日 20:15















