不一样平台上安装nginxjava
1.mac 安装在命令行中输入如下命令, 前提安装好brewlinux
brew install nginx
2.Linux centos安装linuxnginx
先须要安装源:centos
rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm yum install nginx
启动nginxsocket
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"spa
缘由是: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)命令行
可经过下面命令来启动nginxcode
nginx -c /etc/nginx/nginx.conf
2.运行service nginx start 启动nginx出现Starting nginx: nginx: [emerg] open() "/var/run/nginx.pid" failed (13: Permission denied) 是由于权限的设置问题致使server
可经过下面命令来启动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之旅吧!