- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个带有 Rails 4 应用程序的 VPS,在带有 NginX 和 Unicorn 的 Ubuntu 上运行。
因为我希望所有页面都受 SSL 保护,所有对 http://
的请求都被转发到工作正常的 https://
。
这是我的 NginX 配置:
user www-data;
worker_processes 4;
pid /var/run/nginx.pid;
events { worker_connections 1024; }
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
server_tokens off;
server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_disable "msie6";
gzip_types text/plain text/xml text/css text/comma-separated-values;
upstream app_server { server 127.0.0.1:8080 fail_timeout=0; }
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
server {
listen 80;
server_name myapp.com;
rewrite ^ https://$server_name$request_uri? permanent;
}
server {
listen 443;
server_name myapp.com;
root /home/rails/public;
index index.htm index.html;
ssl on;
ssl_certificate /etc/ssl/myapp.com.crt;
ssl_certificate_key /etc/ssl/myapp.com.key;
location / {
try_files $uri/index.html $uri.html $uri @app;
}
location @app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $host;
proxy_pass http://app_server;
}
}
}
我怎样才能将对 http://myapp.com
和 https://myapp.com
的所有请求都转发到 https://www.myapp.com
?
感谢您的帮助。
最佳答案
您可以通过两种方式进行:
www
并基于此提供 30(1|2) 重定向(可能是最简单的)。在 Nginx 中创建一个额外的虚拟主机,监听 myapp.com
并且只让它重定向到 www.myapp.com
。
服务器{ 听 443; 服务器名称 myapp.com; [添加 ssl 配置] 返回 301 https://www.myapp.com $request_uri;
关于ruby-on-rails - 如何添加 www.使用 NginX 和 SSL 域名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24148126/
以下帖子可能看起来相同,但在尝试作为答案提供的所有解决方案后,我无法纠正问题。(Login failed for user 'DOMAIN\MACHINENAME$') 我的问题 我正在 Window
域名、虚拟主机是什么意思?有的新手用户不理解,为什么做网站要买域名和空间才行。这里我们来分别介绍下域名和虚拟主机。 关于域名 域名通俗的说,就是你网站的名号,你注册域名之后就以这个名号去宣传
我有一台具有2个域名的服务器(比如domain1.com和domain2.com)。 我可以通过ssh user@domain1.com和ssh user@domain2.com SSH进入服务器。我
我已经设置了一个 Ubuntu LAMP 服务器,并且我的网站可以正常运行 phpmyadmin。但是,我最近不得不为我的 IP 地址创建一个虚拟主机,以避免 Tomcat 中的目录列表出现安全问题,
Nginx可以为某一个域名单独加用户认证,具体做法如下: 1. 生成用户认证的用户名和密码: 复制代码代码如下: #wget -c soft.vpser.net/ln
Centos中基于IP的虚拟主机搭建 首先,检查是否已安装httpd软件包 安装httpd软件包 安装完成 启动服务 主配置文件是/etc/httpd/conf/htt
1、什么是泛域名解析? 泛域名解析是指将*.域名解析到同一IP。 在域名前添加任何子域名,均可访问到所指向的WEB地址。也就是客户的域名a.com之下所设的*.a.com全部解析到同一个IP地
我知道 WordNet 有域层次结构:例如运动->足球。 1) 是否可以列出所有与“sport->football”子域相关的单词? Response: goalkeeper, forward,
我正在尝试为我正在处理的项目的 URL 缩短器设置一个带有 .ka 后缀的域。例如类似于 drbl.in。我在网上查了一下,这个后缀似乎还没有在任何国家注册过,也没有出现过任何域名服务。关于如何解决这
我在设置 Openfire 时遇到问题。 Openfire 设置中的默认 XMPP 域名显示我的计算机名称,因此每当我通过 Spark 进行测试时,它都不起作用。 我尝试了我拥有的域,但在 openf
我正在使用 Joomla 的 JSN Uniform 插件来接收电子邮件,但它不接受 .company 域作为有效域。它接受常用域(com、net、org、info、biz 等),但不接受 .comp
我创建了一个域名并将其重新定义为您的外部 IP 地址。同时启动 nginx 和 tomcat。将域重新定义为外部 IP 地址。 truckpart4you.com:8081/spring 我想隐藏80
与子域相反。 我试过了。 var a = window.location.hostname.match(/(www.)?([^\.]*)\./)[2]; 但这会抢 frozen-dusk-2587
我正在使用 django 的 send_mail 发送一封电子邮件(使用模板),其中包含以下行: 要重置密码,请点击以下链接: http://localhost:8000/{% url 'reset_
来自 Scrapy 教程: domain_name: identifies the Spider. It must be unique, that is, you can’t set the same
一个快速简单的正则表达式问题 我在字符串中有一个域名,我需要删除它 - 总是有 http://www. 并且域总是以“/”结尾 g_adv_fullpath_old = g_adv_fullpath_
我需要 xslt 版本 2 在记录或元素级别为“xml”属性前缀 (xml:lang="en-us") 生成域名: xmlns:xml="http://www.w3.org/XML/1998/name
如何获取机器的域名(如果机器实际上已加入域)? 当然,如果机器没有加入域,函数应该返回 null,或 空字符串,或 机器的名称,或 "." 注意事项: NetGetJoinInformation Wi
这个手机号码正则验证函数可以说是最新的都支持的,里面有详细的介绍说明,不论以后增加什么号段大家都非常容易的稍微修改一下即可。 javascript 手机号码正则表达式验证函数 复制代码 代码如下:
我使用 Google 域在 Github Pages 上托管我的网站,在 Chrome 中的 iPhone 上运行完美 但是在我的桌面上,Chrome(我的普通浏览器(我确实检查了缓存))或 Fire
我是一名优秀的程序员,十分优秀!