本文主要介紹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