系統環境:CentOS 6.8 64-bit
#> vi /etc/yum.repos.d/nginx.repo [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/6/$basearch/ gpgcheck=0 enabled=1 #> yum install nginx
/etc/nginx/nginx.conf:
############################################# # 這是 Nginx 服務的主要設定檔 # 檔案位置預設為 /etc/nginx/nginx.conf ############################################# # 啟用程序的 Linux 帳戶 user nginx; # 啟用的執行緒數量(建議為你的 CPU 核心數 x 2) worker_processes 2; # Error Log 檔的位置 error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { # 允許同一時間連線總數量 worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; # 預設的 log 記錄格式 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 檔的位置 access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; # 預設不會自動啟動 gzip 壓縮 #gzip on; # 載入 /etc/nginx/conf.d/ 下的所有設定檔 # 通常都是各個虛擬主機的配置 include /etc/nginx/conf.d/*.conf; }
/etc/nginx/conf.d/default.conf:
server { # 這個虛擬主機的 Port 和名稱 listen 80; server_name localhost; # 預設編碼,但通常不建議開啟,讓網頁中的 meta 或 header 自行定義 #charset koi8-r; # 可以額外針對這個站台修改 log 的存放位置 #access_log /var/log/nginx/log/host.access.log main; # 根目錄的設定 location / { # 實際的檔案位置 root /usr/share/nginx/html; # 預設首頁檔名 index index.html index.htm; } # 如果發生 404 可以指定到特定的頁面來顯示 #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} }
#> service nginx start