1. 程式人生 > >NGINX+PHP配置

NGINX+PHP配置

嘗試 lena .html status fast esc root www. path_info

NGINX做為WEB服務器,運行PHP開發的程序和頁面:

server {
listen 80;
listen 443 ssl;

ssl_certificate /usr/local/nginx/conf/ssl/ccgplay.crt;
ssl_certificate_key /usr/local/nginx/conf/ssl/ccgplay.key;


ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;

ssl_prefer_server_ciphers on;
ssl_session_timeout 10m;
ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_buffer_size 1400;
add_header Strict-Transport-Security max-age=15768000;
ssl_stapling on;
ssl_stapling_verify on;
server_name www.cc.com;

log_format main escape=json ‘{ "@timestamp": "$time_iso8601", ‘
‘"remote_addr": "$remote_addr",‘
‘"request_time": "$request_time",‘
‘"upstream_response_time": "$upstream_response_time",‘
‘"status": $status,‘
‘"x_forwarded": "$http_x_forwarded_for",‘
‘"http_referer": "$http_referer",‘
‘"request": "$request",‘
‘"upstream_addr": "$upstream_addr",‘
‘"body_bytes_sent":$body_bytes_sent,‘
‘"request_body":$request_body,‘
‘"http_user_agent": "$http_user_agent" }‘;


access_log /weblogs/cc.com_nginx.log combined;
index index.php;
include /usr/local/nginx/conf/rewrite/thinkphp.conf;
root /web/cc.com;

error_page 400 /errpage/400.html;
error_page 403 /errpage/403.html;
error_page 404 /errpage/404.html;
error_page 503 /errpage/503.html;
location / {
include /web/cc.com/.htaccess;
index index.php;

#如果文件不存在則嘗試TP解析
}
location ~ .*\.(wma|wmv|asf|mp3|mmf|zip|rar|jpg|gif|png|swf|flv|mp4)$ {
valid_referers none blocked *.ccgplay.com new.ccgplay.com;
if ($invalid_referer) {
return 403;
}
}
location ~ .+\.php($|/) {
root //web/ccgplay.com;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;

#設置PATH_INFO,註意fastcgi_split_path_info已經自動改寫了fastcgi_script_name變量,
#後面不需要再改寫SCRIPT_FILENAME,SCRIPT_NAME環境變量,所以必須在加載fastcgi.conf之前設置
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;

#加載Nginx默認服務器環境變量配置
include fastcgi.conf;
}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
expires 30d;
access_log off;
}
location ~ .*\.(js|css)?$ {
expires 7d;
access_log off;
}
location ~ /\.ht {
deny all;
}
}

NGINX+PHP配置