nginx配置反向代理服务
server {
listen 80;
server_name abc.com;
location / {
proxy_pass http://localhost:8080/;
index index.html;
}
}
nginx配置h5项目,静态文件访问
server {
listen 80;
server_name abc.com;
location / {
root /home/www/h5;
index index.html;
}
}
nginx通过添加代理请求头的方式,传递访问者的ip地址给后端服务
server {
listen 80;
server_name abc.com;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Real-PORT $remote_port;
proxy_set_header host $host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8080/;
index index.html;
}
}
nginx配置反向代理和https
server {
listen 443 ssl;
server_name abc.com;
ssl_certificate /ssl/abc.pem; # 可以是pem或者crt证书文件
ssl_certificate_key /ssl/abc.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Real-PORT $remote_port;
proxy_set_header host $host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8080/;
}
}
nginx配置http自动跳转到https
server {
listen 80;
server_name abc.com;
rewrite ^(.*) https://abc.com$request_uri? permanent;
}
© 版权声明
THE END