待完成
nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
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 /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
proxy_cache_path /var/nginx/cache levels=1:2 keys_zone=container:10m max_size=200m inactive=60m use_temp_path=off;
server {
listen 80 default_server;
server_name _;
root /usr/share/nginx/html;
include /etc/nginx/default.d/*.conf;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#proxy_pass http://XXX.XXX.elb.amazonaws.com/;
proxy_set_header Host $host;
proxy_cache container;
proxy_cache_valid 200 302 3d;
proxy_cache_valid 404 1m;
proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
proxy_cache_background_update on;
proxy_cache_lock on;
#proxy_cache_path /var/nginx/cache levels=1:2 keys_zone=container:10m max_size=200m inactive=60m use_temp_path=off;
proxy_temp_path /var/nginx/tmp;
proxy_cache_revalidate on;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
##
# Gzip Settings
##
gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
}
amazon-linux-extras install nginx1 -y
systemctl enable nginx.service
sudo mkdir -p /var/nginx/cache
cd /etc/nginx
mv nginx.conf nginx.conf.bk
curl -o nginx.conf https://XXXX.xxx.xxx
sed -i '42i proxy_pass https://www.google.com.tw;' nginx.conf
sudo systemctl restart nginx.service
Curl 監控網頁
watch -n 0.5 "curl -Is www.google.com | head -n 1"