本文主要介绍CentOS下的Nginx安装过程,源码安装参看官方文档。
- 使用root权限安装
yum install nginx - 配置文件
vi /etc/nginx/nginx.conf
例如,下面是一个类似ftp的http file server的nginx配置:
worker_processes 1;
error_log /var/log/nginx/error.log info;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
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 /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
# Load config files from the /etc/nginx/conf.d directory
# The default server is in conf.d/default.conf
include /etc/nginx/conf.d/*.conf;
server {
listen 8080; # 服务的监听端口
server_name 10.12.13.12; # 服务器名称
root /opt/mydata; # 数据的发布目录
autoindex on; # 是否自动建索引
autoindex_exact_size off; # 关闭计算文件确切大小(单位bytes),只显示大概大小
autoindex_localtime on; # 显示本机时间而非 GMT 时间
}
}
- 启动服务
service nginx start
/etc/init.d/nginx start - 停止服务
service nginx stop
/etc/init.d/nginx stop - 服务的启动停止
chkconfig --add nginx
chkconfig nginx on