[nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=0 enabled=1
# yum install nginx Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirror01.idc.hinet.net * extras: mirror01.idc.hinet.net * updates: mirror01.idc.hinet.net nginx | 2.9 kB 00:00 nginx/primary_db | 24 kB 00:00 Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package nginx.x86_64 0:1.4.2-1.el6.ngx will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================================================================================================================= Package Arch Version Repository Size ================================================================================================================================================================================= Installing: nginx x86_64 1.4.2-1.el6.ngx nginx 311 k Transaction Summary ================================================================================================================================================================================= Install 1 Package(s) Total download size: 311 k Installed size: 770 k Is this ok [y/N]: y Downloading Packages: nginx-1.4.2-1.el6.ngx.x86_64.rpm | 311 kB 00:01 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : nginx-1.4.2-1.el6.ngx.x86_64 1/1 ---------------------------------------------------------------------- Thanks for using NGINX! Check out our community web site: * http://nginx.org/en/support.html If you have questions about commercial support for NGINX please visit: * http://www.nginx.com/support.html ---------------------------------------------------------------------- Verifying : nginx-1.4.2-1.el6.ngx.x86_64 1/1 Installed: nginx.x86_64 0:1.4.2-1.el6.ngx Complete!
mkdir /var/nginx mkdir /var/nginx/cache
# vi /etc/nginx/nginx.conf user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { proxy_cache_path /var/nginx/cache levels=1:2 keys_zone=STATIC:10m inactive=24h max_size=1g; client_max_body_size 10G; server { location / { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://xxx.xxx.xxx.xxx; proxy_set_header Host $host; proxy_cache STATIC; proxy_cache_valid 200 1d; proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504; } } include /etc/nginx/conf.d/*.conf; }
# vi /etc/nginx/nginx.conf user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { proxy_cache_path /var/nginx/cache levels=1:2 keys_zone=STATIC:10m inactive=24h max_size=1g; client_max_body_size 10G; sendfile on; tcp_nopush on; keepalive_timeout 600; tcp_nodelay on; upstream backend { server {your-backend-server1}:80; server {your-backend-server2}:80; } server { location / { add_header X-Proxy-Cache $upstream_cache_status; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://backend; proxy_set_header Host $host; proxy_cache_key "$scheme$host$request_uri"; proxy_cache STATIC; proxy_cache_valid 200 1d; proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504; proxy_connect_timeout 6000; proxy_send_timeout 6000; proxy_read_timeout 6000; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; send_timeout 6000; proxy_buffering off; } gzip on; gzip_min_length 1k; gzip_buffers 4 16k; #gzip_http_version 1.0; gzip_comp_level 2; gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php; gzip_vary off; gzip_disable "MSIE [1-6]\."; } include /etc/nginx/conf.d/*.conf; }
# service nginx restart # chkconfig nginx on
sudo apt update sudo apt install nginx