2019-05-24 13:59:43 2711瀏覽
今天千鋒扣丁學(xué)堂Linux培訓(xùn)老師給大家分享一篇關(guān)于使用SSL配置Nginx反向代理指南,首先反向代理是一個(gè)服務(wù)器,它接收通過Web發(fā)出的請求,即http和https,然后將它們發(fā)送到后端服務(wù)器(或服務(wù)器)。后端服務(wù)器可以是單個(gè)或一組應(yīng)用服務(wù)器,如Tomcat,wildfly或Jenkins等,或者甚至可以是其他Web服務(wù)器,如Apache等。
$ openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/certs/cert.key -out /etc/nginx/certs/cert.crt
$ sudo apt-get update && sudo apt-get install nginx
# systemctl start nginx # systemctl enable nginx
server { listen 80; return 301 https://$host$request_uri; } server { listen 443; server_name linuxtechlab.com; ssl_certificate /etc/nginx/ssl/cert.crt; ssl_certificate_key /etc/nginx/ssl/cert.key; ssl on; ssl_session_cache builtin:1000 shared:SSL:10m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4; ssl_prefer_server_ciphers on; access_log /var/log/nginx/access.log; location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_pass http://localhost:8080; proxy_read_timeout 90; proxy_redirect http://localhost:8080 https://linuxtechlab.com; } }
server { listen 80; return 301 https://$host$request_uri; }
listen 443; server_name linuxtechlab.com; ssl_certificate /etc/nginx/ssl/cert.crt; ssl_certificate_key /etc/nginx/ssl/cert.key; ssl on; ssl_session_cache builtin:1000 shared:SSL:10m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4; ssl_prefer_server_ciphers on;
location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_pass http://localhost:8080; proxy_read_timeout 90; proxy_redirect http://localhost:8080 https://linuxtechlab.com; }
# nginx -t
# systemctl restart nginx
【關(guān)注微信公眾號獲取更多學(xué)習(xí)資料】 【掃碼進(jìn)入HTML5前端開發(fā)VIP免費(fèi)公開課】
查看更多關(guān)于“Linux培訓(xùn)資訊”的相關(guān)文章>>