安装Nginx

来源:互联网 发布:优化教育环境 编辑:程序博客网 时间:2024/06/05 19:04



想在linux 上装个nginx,于是网上找资料整理如下:


首先要添加一个资源库,命令:
vim /etc/yum.repos.d/nginx.repo


用vim 打开/etc/yum.repos.d/nginx.repo ,如果nginx.repo 不存在,就会去创建这个文件。
然后复制黏贴下面几行代码到nginx.repo,保存退出即可。


[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1


保存后,用yum 命令安装nginx,命令:
yum install nginx


经过一段时间的安装,会提示Complete!表示安装完成。
然后启动 nginx 服务
service nginx start


提示:
Job for nginx.service failed. See 'systemctl status nginx.service' and 'journalctl -xn' for details


然后去找了一下log:
cat /var/log/messages | grep nginx
显示如下:
Jul 19 12:29:30 iZ238n3yloaZ systemd: Starting nginx - high performance web server...
Jul 19 12:29:30 iZ238n3yloaZ nginx: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Jul 19 12:29:30 iZ238n3yloaZ nginx: nginx: configuration file /etc/nginx/nginx.conf test is successful
Jul 19 12:29:30 iZ238n3yloaZ nginx: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jul 19 12:29:30 iZ238n3yloaZ nginx: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jul 19 12:29:31 iZ238n3yloaZ nginx: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jul 19 12:29:31 iZ238n3yloaZ nginx: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jul 19 12:29:32 iZ238n3yloaZ nginx: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Jul 19 12:29:32 iZ238n3yloaZ nginx: nginx: [emerg] still could not bind()
Jul 19 12:29:32 iZ238n3yloaZ systemd: nginx.service: control process exited, code=exited status=1
Jul 19 12:29:32 iZ238n3yloaZ systemd: Failed to start nginx - high performance web server.
Jul 19 12:29:32 iZ238n3yloaZ systemd: Unit nginx.service entered failed state.


可以看出是80 端口被占用了,才想起来自己的服务器是apache ,现在正在启动,然后输入命令:
netstat -tunlp | grep 80


显示:
[root@iZ238n3yloaZ ~]# netstat -tunlp | grep 80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      10460/httpd 
果然是被apache 占用。


停止了apache服务,然后开启nginx ,成功。
0 0
原创粉丝点击