CentOS下Nginx安裝

本文主要介紹CentOS下的Nginx安裝過程,源碼安裝參看官方文檔。

  1. 使用root權限安裝
    yum install nginx
  2. 配置文件
    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 時間
        }
    }
    
  3. 啓動服務
    service nginx start
    /etc/init.d/nginx start
  4. 停止服務
    service nginx stop
    /etc/init.d/nginx stop
  5. 服務的啓動停止
    chkconfig --add nginx
    chkconfig nginx on
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章