nginx(一)安装与命令总结

本文介绍了如何在Mac和CentOS上安装Nginx,并提供了启动、重启、检查配置等常用命令。同时针对一些常见的问题提供了详细的解决方案。

nginx(一)安装与命令总结

不同平台上安装nginx

1.mac 安装在命令行中输入以下命令, 前提安装好brew

brew install nginx

2.Linux centos安装linux

先需要安装源:

rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm

yum install nginx

 

启动nginx

service nginx start

 

常用命令总结:

nginx -t;//检查配置文件nginx.conf是否正确
nginx -s reload;//重载配置
nginx -c /etc/nginx/nginx.conf;//启动nginx
ps -ef|grep nginx;//查看nginx进程
service nginx start;//启动nginx
service nginx stop;//关闭nginx

 

常见问题解决方案

1.很多时候我们nginx -s reload 会出现 nginx: [error] invalid PID number "" in "/var/run/nginx.pid"

原因是:nginx -s reload is only used to tell a running nginx process to reload its config. After a stop, you don't have a running nginx process to send a signal to. Just run nginx (possibly with a -c /path/to/config/file)

可通过下面命令来启动nginx

nginx -c /etc/nginx/nginx.conf

2.运行service nginx start 启动nginx出现Starting nginx: nginx: [emerg] open() "/var/run/nginx.pid" failed (13: Permission denied) 是因为权限的设置问题导致

可通过下面命令来启动nginx

nginx -c /etc/nginx/nginx.conf

 

3.  启动nginx 有可能出现下面的错误 Starting nginx: nginx: [emerg] socket() [::]:80 failed (97: Address family not supported by protocol)解决方案修改/etc/nginx/conf.d/default.conf为 删除listen [::]:80 default_server;

listen 80;
listen [::]:80 default_server;

修改之后的结果为

listen       80;
server_name  _;

 

 

通过下面命令查看nginx服务是否启动

ps -ef|grep nginx

 

看到下面的信息说明nginx安装成功了

[root@VM_30_103_centos etc]# ps -ef|grep nginx
root      3294     1  0 Jun21 ?        00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
root     27118  3294  1 13:57 ?        00:00:00 nginx: worker process                   
root     27119  3294  0 13:57 ?        00:00:00 nginx: worker process                   
root     27120  3294  1 13:57 ?        00:00:00 nginx: worker process                   
root     27121  3294  0 13:57 ?        00:00:00 nginx: worker process                   
root     27123 26467  0 13:57 pts/0    00:00:00 grep nginx

下面就开启学习nginx之旅吧!

转载于:https://my.oschina.net/chenxiaobian/blog/714292

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值