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之旅吧!