我正在运行一个Redmine实例,它使用nginx的SSL和apache来提供内容。
我正在通过在新机器上安装最新版本来升级这个版本,一旦完成所有工作,我将复制文件和数据库。
我已经从现有的机器上复制了Apache和Nginx的configuration到新的机器,但结果是不同的两台机器,我不明白为什么。
在目前的生产实例中,Redmine正在18804港口运行(如我的老板所定)。 目前,当有人使用浏览器访问redmine.mydomain.com时,他们会自动使用HTTPSredirect到Redmine。 发生这种情况的原因是:18804是否被追加到末尾,这是我希望如何操作的。
但是,在新机器上,如果在浏览器中inputnewredmine.mydomain.com,我将被redirect到nginxtesting页面。 但是,如果我inputnewredmine.mydomain.com:18804或https://newredmine.mydomain.com ,那么我将使用HTTP路由到应用程序。
我只需input逻辑URL即可完成此操作。 很明显,redirect到HTTPS不工作,但作为configuration是一个确切的副本,我不明白为什么。
当前服务器正在运行Amazon Linux,Apache 2.2.31和nginx 1.10.2。 新的运行Centos 7,Apache 2.4.6和nginx 1.10.2。
这是我的应用程序的configurationnginx:
upstream redmine { server 127.0.0.1:18805; } server { listen 18804; location / { return 301 https://$host$request_uri; } } server { listen 80; location / { return 301 https://$host$request_uri; } } server { listen 443 ssl; server_name application.mydomain.com; access_log /var/log/nginx/redmine.access.log; error_log /var/log/nginx/redmine-errors.log; ssl on; ssl_certificate_key /etc/ssl/private/key; ssl_certificate /etc/ssl/certs/crt; ssl_ciphers RC4:HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; client_max_body_size 0; location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://redmine; } }
和我的服务器块从Apache的情况下是必需的:
# Redmine 3.3.3 <VirtualHost *:18805> DocumentRoot /var/www/html/redmine/public ServerName newredmine.mydomain.com ServerAlias 127.0.0.1 ErrorDocument 503 /maintenance.html RewriteEngine on RewriteCond %{DOCUMENT_ROOT}/../tmp/stop.txt -f RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ /$1 [R=503,L] <Directory /var/www/html/redmine/public/> AllowOverride all # MultiViews must be turned off. Options -MultiViews </Directory> ErrorLog logs/redmine_3.3.3_log
正如我所说的,真正令人困惑的部分是,尽pipe在两者上都有相同的configuration,但两个实例的行为不同。 唯一的区别是你期望的,例如Redmine公共文件夹的位置。
任何人都可以看到我在这里失踪?
您在redirect服务器块上缺lessserver_name
。 因此,nginx上实际的虚拟主机select并不那么清楚。
首先,你需要确保你有一个在listen
指令中有default_server
属性的server
块。 在此块上,您可以定义服务器在接收到未明确configuration的主机的请求时执行的操作。
然后,你需要有这样的server
块来redirect:
server { listen 18804; server_name redmine.mydomain.com; return 301 https://redmine.mydomain.com$uri; } server { listen 80; server_name redmine.mydomain.com; return 301 https://redmine.mydomain.com$uri; }
在return
指令中最好使用显式域名,因为$host
variables在某些时候可能包含不需要的值。
SSL块可以保持现在的样子。