Nginx学习 安装 命令 server配置

【注意】:以下内容是基于旧版nginx,配置信息位置和文件目录和最新版不一致,但依葫芦画瓢是一样的

nginx 的安装

 

下载地址: http://nginx.org/download/nginx-1.4.2.tar.gz

安装准备: nginx依赖于pcre库,要先安装pcre

yum install pcre pcre-devel

 cd /usr/local/src/

 wget http://nginx.org/download/nginx-1.4.2.tar.gz

tar zxvfnginx-1.4.2.tar.gz

cd nginx-1.4.2

./configure --prefix=/usr/local/nginx

make && make install

 

启动:

cd /ulsr/local/nginx, 看到如下4个目录

./

 ....conf配置文件 

 ... html网页文件

 ...logs  日志文件

 ...sbin  主要二进制程序

 

[root@localhost nginx]# ./sbin/nginx

nginx: [emerg] bind() to 0.0.0.0:80 failed(98: Address already in use)

....

nginx: [emerg] bind() to 0.0.0.0:80 failed(98: Address already in use)

nginx: [emerg] still could not bind()

 

不能绑定80端口,80端口已经被占用

(有时是自己装了apache,nginx等,还有更多情况是操作系统自带了apache并作为服务启动)

解决: 把占用80端口的软件或服务关闭即可.

 


Nginx的信号控制

TERM, INT

Quick shutdown

QUIT

Graceful shutdown  优雅的关闭进程,即等请求结束后再关闭

HUP

Configuration reload ,Start the new worker processes with

 a new configuration Gracefully shutdown the old worker processes

改变配置文件,平滑的重读配置文件

USR1

Reopen the log files 重读日志,在日志按月/日分割时有用

USR2

Upgrade Executable on the fly 平滑的升级

WINCH

Gracefully shutdown the worker processes 优雅关闭旧的进程(配合USR2来进行升级)

 

 

                                                                                                                        

具体语法:

Kill -信号选项 nginx的主进程号

Kill -HUP 4873

 

Kill -信号控制 `cat/xxx/path/log/nginx.pid`

 

Kil; -USR1 `cat /xxx/path/log/nginx.pid`

 

 


Nginx配置段

 

// 全局区
worker_processes 1; // 有1个工作的子进程,可以自行修改,但太大无益,因为要争夺CPU,一般设置为 CPU数*核数

 

Event {

// 一般是配置nginx连接的特性

// 如1个word能同时允许多少连接

 worker_connections  1024; // 这是指一个子进程最大允许连1024个连接

}

 

http {  //这是配置http服务器的主要段

     Server1 { // 这是虚拟主机段

      

            Location {  //定位,把特殊的路径或文件再次定位,如image目录单独处理

            }             /// 如.php单独处理

 

     }

 

     Server2 {

     }

}

 

 

例子1: 基于域名的虚拟主机

 

    server {

        listen 80;  #监听端口

        server_name a.com; #监听域名

 

        location / {

                root/var/www/a.com;   #根目录定位

                indexindex.html;

        }

    }

 

例子2: 基于端口的虚拟主机配置

 

    server {

        listen 8080;

        server_name192.168.1.204;

 

        location / {

                root/var/www/html8080;

                indexindex.html;

        }

    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值