1. Update Ubuntu
# add-apt-repository warehouse name # apt-get update# apt-get install-y libssl1. 0.2 OpenSSL
2. Installing Nginx
# apt-Get install-y nginx# apt-get install-y Nginx-extras
3. Setting nginx Universal configuration file
cat/etc/nginx/Nginx.confuser www-data; #ubuntu里面nginx用户名worker_processes auto;pid/run/Nginx.pid;include/etc/nginx/modules-enabled/*. conf;events {worker_connections 1024; # multi_accept on;} HTTP {# # # Basic Settings # # sendfile on; Tcp_nopush on; Tcp_nodelay on; Keepalive_timeout 65; Types_hash_max_size 2048; Server_tokens off; #关闭显示nginx版本 Server_names_hash_bucket_size 64; # server_name_in_redirect off; Include/etc/nginx/mime.types; Default_type Application/octet-stream; # # # SSL Settings # # Ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # dropping SSLv3, Ref:poodle ssl_prefer_server_ciphers on; Ssl_ciphers "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:EECDH+AESGCM : Edh+aesgcm:aes256+eecdh:aes256+edh "; Ssl_ecdh_curve secp384r1; # Requires Nginx >= 1.1.0 ssl_session_cache shared:ssl:10m; Ssl_session_tickets off; # Requires Nginx >= 1.5.9 # ssl_stapling on; # Requires Nginx >= 1.3.7 ssl_stapling_verify on; # Requires Nginx = 1.3.7 # # # Logging Settings # # 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/data/log/nginx/access.log main; Error_log/data/log/nginx/error.log; # # # gzip Settings # # gzip on; Gzip_vary on; Gzip_min_length 1k; Gzip_buffers 4 32k; Gzip_disable "Msie6"; Gzip_disable "MSIE [1-6]."; Gzip_http_version 1.1; Gzip_comp_level 3; Gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/javascript Application/json; # # # Proxy Headers # # include/etc/nginx/proxy.conf; #设置代理头信息 more_set_headers "Server:customer Web Server Header"; # # # Virtual Host configs # # include/etc/nginx/conf.d/*.conf; include/etc/nginx/sites-enabled/*; #配置各个站点的信息}
4. Setting Nginx Agent
cat/etc/nginx/proxy.confproxy_redirect off;proxy_set_header Host $host; #proxy_set_header X -real-IP $remote _addr; #获取真实IPproxy_set_header X-forwarded-for $proxy _add_x_forwarded_for; Get the real ipclient_max_body_size of the agent 10m;client_body_buffer_size 128k;proxy_connect_timeout90 ;p roxy_send_timeout ;p roxy_read_timeout; Proxy_buffer_size 4k;proxy_buffers 4 32k;proxy_busy_buffers_size 64k;proxy_temp_ File_write_size 64k;
5. Setting up Site configuration information
cd/etc/nginx/sites-enabled/
Upstream local_iis_80 {server back-end IP1: themax_fails=2Fail_timeout=10s weight=Ten; Server Back-end IP2: themax_fails=2Fail_timeout=10s weight=Ten; KeepAlive $; #防止出现nginx向后端发请求的时候连接打爆了}upstream local_iis_443 {server Back-end IP1:443max_fails=2Fail_timeout=10s weight=Ten; Server Back-end IP1:443max_fails=2Fail_timeout=10s weight=Ten; KeepAlive $; #防止出现nginx向后端发请求的时候连接打爆了}server {Listen the; CharSet UTF-8; Location/{proxy_pass http://local_iis_80;}}server {Listen443SSL HTTP2; #支持http2 CharSet UTF-8; Ssl_certificate/data/cert/certificates. crt; Ssl_certificate_key/data/cert/certificate. Key; Location/{proxy_pass https://local_iis_443; }}
Ubuntu installation Nginx