nginx 1.9.5 之後就支援 HTTP/2
環境 centos 6.x
YUM 庫
vi /etc/yum.repos.d/nginx.repo
[nginx] name=nginx repo baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/ gpgcheck=0 enabled=1
yum 安裝 nginx
yum install nginx -y
全域 conf 檔
vi /etc/nginx/nginx.conf
# 執行使用者 user nginx; # 執行緒 = 核心數 x2 worker_processes 2; error_log /var/log/nginx/error.log; 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 /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; # 壓縮資料 gzip on; # 跟 apache 一樣可以在 conf.d 定義 .conf include /etc/nginx/conf.d/*.conf; }
預設 conf.d/default.conf 檔
server { # port 與 主機名稱 listen 80; server_name localhost; # 預設編碼 #charset koi8-r; #access_log /var/log/nginx/log/host.access.log main; # 網頁家目錄 location / { # 檔案放置路徑 root /usr/share/nginx/html; # 預設 index 檔順序 index index.html index.htm; } # 404 錯誤導向頁面 #error_page 404 /404.html; }
所以我拿來複製一份 default.conf 為 ssorc1.tw.conf,並修改如下,
並設定支援 php + php-fpm
(先安裝 php-fpm 及 php 套件)
(yum -y install php-fpm php)
server { listen 80; server_name ssorc1.tw; access_log /var/log/nginx/ssorc1.tw.access.log main; error_log /var/log/nginx/ssorc1.tw.error.log; location / { root /var/www/html/ssorc1.tw; index index.html index.htm index.php; } location ~ \.php$ { root /var/www/html/ssorc1.tw; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
啟用
service php-fpm start service nginx start
設定 server-status
server { location /server-status { # Turn on nginx stats stub_status on; # I do not need logs for stats access_log off; # Security: Only allow access from 192.168.1.100 IP # allow 192.168.1.100; # Send rest of the world to /dev/null # deny all; } }
關閉版本
server_tokens off;
留言