Nginx-如何使用在位置块中具有代理的https服务我的静态内容? [英] Nginx- How can I serve my static content with https that has a proxy in location block?

查看:73
本文介绍了Nginx-如何使用在位置块中具有代理的https服务我的静态内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的服务器侦听443端口,并将请求重定向到服务器中的另一个端口.我的服务器还监听80端口,并在用户浏览 http://www.xxxx.com 时向用户显示静态内容>

但是我也想在用户浏览 https://www.xxxx.com <时显示静态内容. /p>

我该如何管理?我的Nginx配置文件是;

server {

   listen 443 ssl; 
   server_name xxxx.com;
   ssl_certificate /etc/nginx/ssl/nginx.crt;
   ssl_certificate_key /etc/nginx/ssl/nginx.key;

   location / {
expires off;
      proxy_pass http://backend;
   }
}

server {
  listen 80;
  listen [::]:80;

   server_name xxxx.com;
   root /var/www/xxxx.com/html;
   index index.html;

   location / {
try_files $uri $uri/=404;
   }
}

当用户使用 https://www.xxxx.com ,我的代理将继续在后端工作

解决方案

您可以调用命名位置作为try_files语句的默认操作.

例如:

location / {
    try_files $uri $uri/ @proxy;
}
location @proxy {
    proxy_pass http://backend;
}

有关详细信息,请参见此文档.

My server listen 443 port and redirects the requests to another port in the server. Also my server listen 80 port and displays a static content the user when they browse http://www.xxxx.com

But I want also to display static content when user browse https://www.xxxx.com

How can I manage this ? My Nginx config file is ;

server {

   listen 443 ssl; 
   server_name xxxx.com;
   ssl_certificate /etc/nginx/ssl/nginx.crt;
   ssl_certificate_key /etc/nginx/ssl/nginx.key;

   location / {
expires off;
      proxy_pass http://backend;
   }
}

server {
  listen 80;
  listen [::]:80;

   server_name xxxx.com;
   root /var/www/xxxx.com/html;
   index index.html;

   location / {
try_files $uri $uri/=404;
   }
}

I want to display my index.html file when user browse my website with https://www.xxxx.com and my proxy will continue to work at backend

解决方案

You can invoke a named location as the default action of your try_files statement.

For example:

location / {
    try_files $uri $uri/ @proxy;
}
location @proxy {
    proxy_pass http://backend;
}

See this document for details.

这篇关于Nginx-如何使用在位置块中具有代理的https服务我的静态内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆