问下在nginx里怎么配置https页面和接口访问

现在网站可以用https访问了,但是接口不通,现在想直接在网址后面加个api来访问接口这种,但是不通,一直报405,然后就想单独监听一个接口,但是访问超时,问下各位大佬是哪个地方有问题?

server {
 listen  80;
 server_name localhost;
#rewrite 301 https://www.lhintro.com$request_uri;
 location / {
 root /root/vue-my/dist;
 try_files $uri $uri/ /index.html last;
 index index.html;
 }
 }
 
 server {
 listen  443 ssl;
 server_name localhost;
  
 ssl_certificate cert/3378874_www.lhintro.com.pem;
 ssl_certificate_key cert/3378874_www.lhintro.com.key;
  
 ssl_session_cache shared:SSL:1m;
 ssl_session_timeout 5m;
  
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 / {
 root /root/vue-my/dist;
 try_files $uri $uri/ /index.html last;
 index index.html;
 }
  
 location /api {
 proxy_pass http://127.0.0.1:3080;
# proxy_set_header Host $http_host;
 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#proxy_set_header X-NginX-Proxy true;
#proxy_set_header Connection "";
 }
 }
  
 server {
 listen  9000 ssl;
 server_name localhost;
  
 ssl_certificate cert/3378874_www.lhintro.com.pem;
 ssl_certificate_key cert/3378874_www.lhintro.com.key;
  
阅读 1.9k
1 个回答

405的状态码一般是指方法不对,即,如该用POST传值的,却用了GET方法,试试查查api的文档或源码,选对的方式就好了。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题