nginx配置代理 , 代理vue前端项目
nginx代理vue项目, nginx的配置文件:
假如访问52ccn.com 代理到后面的vue项目
vue项目路径/www/website/red/admin
nginx ssl证书位置在这个文件夹下面/usr/local/nginx/conf/cert/
然后项目中接口请求统一使用/prod-api/
然后通过nginx代理到对应得http://localhost:9032/ 对应得后台服务接口
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 300;
client_max_body_size 1000m;
server {
listen 80;
server_name 52ccn.com; #需要将domain替换成证书绑定的域名。
rewrite ^(.*)$ https://$host$1; #将所有HTTP请求通过rewrite指令重定向到HTTPS。
location / {
index index.html index.htm;
}
}
server {
listen 443 ssl;
#请求域名
server_name 52ccn.com;
#证书位置在这个文件夹下面/usr/local/nginx/conf/cert/
ssl_certificate /usr/local/nginx/conf/cert/7296768_test.52ccn.com.pem;
ssl_certificate_key /usr/local/nginx/conf/cert/7296768_test.52ccn.com.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
#请求域名然后显示admin下面的前台资源页面
location / {
root /www/website/red/admin;
try_files $uri $uri/ /index.html;
index index.html index.htm;
proxy_set_header Host $http_host;
}
#前台资源接口如果有/prod-api/ 开头的接口 走下面的代理9032服务器
location /prod-api/{
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:9032/;
}
#前台资源接口如果有/dev-api/ 开头的接口 走下面的代理9032服务器
location /dev-api/{
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:9032/;
}
#前台资源接口如果有/ysy-api/ 开头的接口 走下面的https://open.ys7.com/服务器
location /ysy-api/ {
proxy_pass https://open.ys7.com/;
}
#前台资源接口如果有/mino-api/ 开头的接口 走下面的代理9032服务器
location /mino-api/ {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:9000/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
HTTP访问自动跳转到HTTPS页面
server {
listen 80;
server_name 52ccn.com; #需要将domain替换成证书绑定的域名。
rewrite ^(.*)$ https://$host$1; #将所有HTTP请求通过rewrite指令重定向到HTTPS。
location / {
index index.html index.htm;
}
}
这样访问52ccn.com 就自动跳https://52ccn.com 上了
分类:
nginx
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了