Nginx-如何使用在位置块中有代理的 https 提供我的静态内容? [英] Nginx- How can I serve my static content with https that has a proxy in location block?
问题描述
我的服务器监听 443 端口并将请求重定向到服务器中的另一个端口.我的服务器也侦听 80 端口并在用户浏览 http://www.xxxx.com
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
但我还想在用户浏览 https://www.xxxx.com
我该如何管理?我的 Nginx 配置文件是 ;
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;
}
}
我想在用户使用 https://www.xxxx.com<浏览我的网站时显示我的 index.html 文件/a> 并且我的代理将继续在后端工作
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
推荐答案
您可以调用命名位置作为 try_files
语句的默认操作.
You can invoke a named location as the default action of your try_files
statement.
例如:
location / {
try_files $uri $uri/ @proxy;
}
location @proxy {
proxy_pass http://backend;
}
有关详细信息,请参阅本文档.
See this document for details.
这篇关于Nginx-如何使用在位置块中有代理的 https 提供我的静态内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!