nginx(一)安裝與命令總結

nginx(一)安裝與命令總結

不一樣平臺上安裝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之旅吧!

相關文章
相關標籤/搜索