Linux中Nginx的配置檔案nginx.conf詳解
阿新 • • 發佈:2019-01-06
原文地址:https://blog.csdn.net/GP_666/article/details/79971198
user www www; #制定nginx 執行的使用者名稱和使用者組
worker_processes 4; #nginx 程序數 建議設定成 CPU幾核 這裡設定成幾
#error_log logs/error.log; 全域性錯誤日誌型別 【debug| info|notice | warn| error|alert|crit 】級別從低到高
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid; nginx 程序檔案
events { #參考事件模型
worker_connections 1024; #單個程序最大連線數 最大連線數 = 連線數* 程序數 根據硬體調整 只要別讓 cpu 100%
keepalive_timeout 65; #連線超時時間
}
http {
include 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 logs/access.log main; 訪問 日誌 路徑
sendfile on; #開啟高效檔案傳輸模式 off 是關閉
#tcp_nopush on; #是否允許 使用socket TCP_CORK 選項
#keepalive_timeout 0;
keepalive_timeout 65;#連線超時時間
#gzip on; 開啟gzip 壓縮 速度更快
server {
listen 8080; #監聽的埠號
server_name localhost; #www.baidu.com baidu.com
#charset koi8-r; #字符集
#access_log logs/host.access.log main; 日誌檔案
root /data/www; #根路徑
location / { #好比grep location / 表示 匹配 使用者輸入的 www.baidu.com baidu.com 及以這個開頭的所有請求 www.baidu.com/index.html baidu.com/123.jpg
#root /data/www;
index index.php index.html index.htm; #預設首頁
}
location ~ \.php$ { ~ 區分大小寫 ~* 不區分大小寫 特殊字元要轉義
#root /data/www; #跟目錄
fastcgi_pass 127.0.0.1:9000; nginx 跟 php之間 交流通過 9000埠
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
#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 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;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
include /usr/local/nginx/conf/vhost/*.conf;
}
借鑑lnmp https 安裝 步驟 lnmp ssl add 新增證書