编辑
2023-11-22
笔记
0

目录

配置文件路径
跨域问题
转发真实 IP
代理转发
创建 HTTP 身份验证文件

配置文件路径

根据请求的Url查找配置文件里的Url匹配选项,去增加选项

shell
# OpenResty /usr/local/openresty/nginx/conf/conf.d/*.conf # Nginx /etc/nginx/conf.d/*.conf

跨域问题

proxy_set_header Access-Control-Allow-Origin *.uing.vip; proxy_set_header Access-Control-Allow-Credentials true; proxy_set_header Access-Control-Allow-Headers: Origin,X-Requested-With,Content-Type,Accept,Authorization; proxy_set_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,OPTIONS,PATCH;

转发真实 IP

proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-Port $remote_port; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

代理转发

location /ws { if ($http_upgrade != "websocket") { return 404; } proxy_pass http://127.0.0.1:1080; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }
server { listen 80 default_server; listen [::]:80 default_server; return 301 https://$host$request_uri; } server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name uing.vip; ssl_certificate /etc/ssl/cert.pem; ssl_certificate_key /etc/ssl/key.pem; ssl_client_certificate /etc/ssl/certificate.crt; ssl_verify_client on; ssl_session_timeout 1d; ssl_session_cache shared:MozSSL:10m;# about 40000 sessions ssl_session_tickets off; # intermediate configuration ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384; ssl_prefer_server_ciphers off; # HSTS (ngx_http_headers_module is required) (63072000 seconds) add_header Strict-Transport-Security "max-age=63072000" always; root /var/www/html; index index.html index.htm index.nginx-debian.html; location / { try_files $uri $uri/ =404; } location /XXX { if ($http_upgrade != "websocket") { return 404; } proxy_redirect off; proxy_pass http://127.0.0.1:10000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }

创建 HTTP 身份验证文件

bash
sudo apt install apache2-utils -y htpasswd -Bc htpasswd cainiao # 输入密码

本文作者:菜鸟

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0) 许可协议。转载请注明出处!