nginx安装
先准备安装好gcc, openssl-devel,pcre-devel, zlib-devel
然后下载nginx 程序进行安装
wget http://nginx.org/download/nginx-0.7.69.tar.gz
tar …
./configure –prefix=/opt/nginx
make && make install
主配置文件
在/opt/nginx/conf/目录下,主要配置文件是nginx.conf
user nobody; #制定nginx进程的所属者和组,默认是nobody
error_log logs/error.log debug; #指定日志的级别debug->info->notice->warn->error->cati
pid logs/nginx.pid; #进程ID存储文件的位置
#设置nginx的工作模式和连接数上限
event {
use epoll; 指定工作模式,linux默认是epoll模式
worker_connections 1024; 每个进程的最大连接数
}
HTTP服务全局配置
http {
include mime.types;
default_type application/octet-stream; #默认类型为2进制流
#Nginx的HttpLog模块,指定nginx的日志输出格式 main为个格式的名称
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main; 调用格式名称
sendfile on; #开启高效文件传输模式
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65; #服务器和客户端之间的保活超时时间
#gzip on; #开始起gzip压缩,实时压缩输出数据流
server配置
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
}
常用维护命令
[root@localhost sbin]# ./nginx -t #通过此命令检查配置文件是否正确
nginx: the configuration file /opt/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /opt/nginx/conf/nginx.conf test is successful
“`
启动程序
[root@localhost sbin]# ./nginx
[root@localhost sbin]# ps -ef | grep nginx
root 23618 1 0 09:55 ? 00:00:00 nginx: master process ./nginx
nobody 23619 23618 0 09:55 ? 00:00:00 nginx: worker process
然后访问本机出现如下网页及正常
Nginx对进程的控制:
1. HUP :重新加载配置文件,不影响接受用户请求,实现平滑重启nginx ->kill -HUP pid
2. USR1 :用于nginx日志切换,重新打开一个日志文件
安装后的文件夹说明
[root@localhost nginx]# ls
client_body_temp conf fastcgi_temp html logs proxy_temp sbin scgi_temp uwsgi_temp
sbin目录下是命令工具
logs下保存有access.log,error.log等
html: 保存页面配置信息