老师这个上线对应nginx规则怎么写?

来源:22-5 Nginx 环境处理

春去_秋来

2022-08-27

vite.config.js
      '/prod-api': {
        target: 'http://abc.com/',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/prod-api/, 'api')
      }
nginx配置文件
location /prod-api {
    rewrite ^/prod-api /api last; # 试了很多种写法没用
}
写回答

1回答

Sunday

2022-08-28

你好

可以参考下我这边上线的 nginx 配置:

# 慕课网 imooc-front

server {

#SSL 访问端口号为 443

listen 443 ssl;

#填写绑定证书的域名

server_name  imooc-front.lgdsunday.club;

#证书文件名称

ssl_certificate imooc-front.lgdsunday.club_bundle.crt;

#私钥文件名称

ssl_certificate_key imooc-front.lgdsunday.club.key;

ssl_session_timeout 5m;

#请按照以下协议配置

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

#请按照以下套件配置,配置加密套件,写法遵循 openssl 标准。

ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;

ssl_prefer_server_ciphers on;

root   /sunday/imooc/front/dist/;

#charset koi8-r;


access_log  logs/host.access.log  main;



location / {

# index  index.html index.htm;

try_files $uri $uri/ /index.html;

}


# 反向代理,解决跨域问题(单独代理请求到服务端)

location /prod-api/ {

proxy_pass http://39.105.131.75:3005/api/;

# $host 变量,Host 为变量名

proxy_set_header   Host              $host; #域名转发

proxy_set_header   X-Real-IP         $remote_addr; #IP转发                        

proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;

proxy_set_header   Cookie            $http_cookie; # cookie 配置

}


}


0
2
Sunday
回复
春去_秋来
我不太明白你的意思? vite 和 nginx 没有任何关系。
2022-08-28
共2条回复

基于 Vue3 ,打造前台+中台通用开发提效解决方案

42 种前台常见业务模型, 15 种中台通用组件,成为前端提效高手

788 学习 · 517 问题

查看课程