1. nginx 安装
sudo yum install nginx
2. nginx 配置
a. nginx.conf
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
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;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
}
2. 到conf.d增加.conf文件
abc.com 域名
# Forward http to https server { listen 80; server_name www.abc.com abc.com; return 301 https://www.abc.com$request_uri; } # Settings for a TLS enabled server. # server { listen 443 ssl http2 default_server; listen [::]:443 ssl http2 default_server; server_name www.vivalachia.com vivalachia.com; # root index.html; ssl_certificate "conf.d/cert_abc/214018423250118.pem"; ssl_certificate_key "conf.d/cert_abc/214018423250118.key"; ssl_session_cache shared:SSL:1m; ssl_session_timeout 10m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; location ~ .*.(html|gif|jpg|jpeg|bmp|png|ico|txt|js|css|woff|woff2|ttf|mp4)$ { root /opt/abc/static; expires 7d; } location /servlet/ { 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_set_header X-Forwarded-Port $server_port; proxy_pass http://localhost:8080; } }
3. http 转向 https
# Forward http to https server { listen 80; server_name www.abc.com abc.com; return 301 https://www.abc.com$request_uri; }
4. ssl 配置
ssl_certificate "conf.d/cert_abc/214018423250118.pem"; ssl_certificate_key "conf.d/cert_abc/214018423250118.key"; ssl_session_cache shared:SSL:1m; ssl_session_timeout 10m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on;
5. 动静分离
location ~ .*.(html|gif|jpg|jpeg|bmp|png|ico|txt|js|css|woff|woff2|ttf|mp4)$ { root /opt/vivalachia/static; expires 7d; } location /servlet/ { 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_set_header X-Forwarded-Port $server_port; proxy_pass http://localhost:8080; }