# 服務運行帳戶設定 User daemon Group daemo # 啓用經常使用模塊 LoadModule php5_module modules/libphp5.so #php支持模塊 LoadModule rewrite_module modules/mod_rewrite.so #URL重寫模塊 Addtype application/x-httpd-php .php # 添加PHP的MIMETYPE DirectoryIndex index.php index.html index.htm # 默認頁配置 PidFile /var/run/httpd.pid # 進程文件設定
# Apache 2.2系列版本 <VirtualHost *:80> DocumentRoot /srv/www/site1 ServerName sitename.com ServerAlias aliasname1.com aliasname2.com #可選(common日誌格式) ErrorLog /var/log/httpd/sitename_error.log #如未指定,則使用全局配置ErrorLog CustomLog /var/log/httpd/sitename_access.log common #可選 <Directory /srv/www/site1> Options MultiViews FollowSymLinks AllowOverride All Order allow,deny Allow From All </Directory> </VirtualHost> # Apache 2.4系列版本 <VirtualHost *:80> DocumentRoot /srv/www/site1 ServerName sitename.com ServerAlias aliasname1.com aliasname2.com #可選(common日誌格式) ErrorLog /var/log/httpd/sitename_error.log #如未指定,則使用全局配置ErrorLog CustomLog /var/log/httpd/sitename_access.log common #可選 <Directory /srv/www/site1> Options FollowSymLinks AllowOverride all Require all granted </Directory> </VirtualHost>
4種系統內置的服務日誌格式:
|格式分類|格式簡寫|用途說明|
|:-----|:------|:------|
|普通日誌格式(common log format,CLF)|common|記錄常規的請求信息|
|參考日誌格式(referer log format)|referer|在常規信息基礎上增長來源頁信息|
|代理日誌格式(agent log format)|agent|在常規信息基礎上增長代理信息|
|綜合日誌格式(combined log format)|combined|結合以上三種日誌信息|php
格式 RewriteRule Pattern Substitution [flags]
html
Substitution:linux
flag:nginx
# 301跳轉, R=permanent 進行永久重定向 RewriteRule Pattern Substitution [R=permanent,L] # 302跳轉, 要求Substitution以http://開頭 RewriteRule Pattern Substitution [R,L] # 圖片防盜鏈 RewriteEngine on RewriteCond %{HTTP_REFERER} !^$ [NC] RewriteCond %{HTTP_REFERER} ! http://www.你的域名.com [NC] RewriteCond %{HTTP_REFERER} ! http://www.baidu.com [NC] RewriteCond %{HTTP_REFERER} ! http://www.google.com [NC] RewriteRule .*\.(gif|jpg|jpeg|bmp|png)$ http://www.你的域名.com/unfind.jpg [R,NC,L]
http response header
中,需引入 Access-Control-Allow-Origin
來受權瀏覽器跨域訪問第三方網站。# 啓用header模塊 LoadModule headers_module modules/mod_headers.so # 虛擬主機配置 Header set Access-Control-Allow-Origin http://other_domain.com
user nobody; # 指定服務運行用戶 worker_processes 4; # 工做進程數設定(通常和cpu數一致) # 全局錯誤日誌 #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; # 進程文件指定 keepalive_timeout 60; #工做模式設定 events { use epoll; # linux2.6+內核可設定epoll(多路複用io)模式提升性能 worker_connections 1024; # 每一個工做進程的併發鏈接數 } http { # 日誌格式設定 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; # 全局日誌設定 gzip on; # 開啓gzip壓縮 # 虛擬主機配置 server { listen 80; server_name www.site.com; root /service/www; access_log logs/nginx.access.log main; # 當前虛擬主機訪問日誌 # php腳本處理 location ~ .php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } }
nginx併發總數 = worker_processes * worker_connections
(反向代理通常會使併發性能下降4倍)apache
server_name
高級配置server_name a.site.com b.site.com;
server_name *.site.com;
server_name ~^(?<hostname>.+?)\.site\.com$;捕獲的變量可經過
$hostname
形式在配置文件中使用