【发布时间】:2019-01-30 19:32:15
【问题描述】:
我在https://hostname.example 上运行一个网站
但是所有请求都通过https://hostname.example:443(该网站的前任开发人员告诉它应该在没有ssl端口的情况下使用主机名)
这似乎对网站产生了不好的影响——某些功能不起作用。
例如,
信息:
CentOS 6.8。
nginx 1.10.2
ssl 证书存在并配置(不是我)
问题是:
- 为什么之前没有通过 ssl 端口的所有请求都开始了?
- 如何解决这个问题并让所有请求只通过主机名?
请告诉我在问题中还包括什么来澄清问题。
UPD。
default.conf
#
# The default server
#
server {
listen 80 default_server;
# listen [::]:80 default_server;
server_name www.hostname.example;
return 301 https://$server_name$request_uri;
#root /path/to/root;
#index index.php index.html;
# Load configuration files for the default server block.
#include /etc/nginx/default.d/*.conf;
#location ~ ^/purge(/.*) {
# allow 127.0.0.1;
# allow 192.168.118.10;
# deny all;
# fastcgi_cache_purge portalName $request_method$http_if_modified_since$http_if_none_match$host$1;
#}
#location / {
#}
#error_page 404 /404.html;
# location = /40x.html {
#}
#error_page 500 502 503 504 /50x.html;
# location = /50x.html {
#}
#location ~ \.php$ {
# fastcgi_cache portalName;
# fastcgi_cache_valid 200 301 302 304 60m;
# fastcgi_cache_key "$request_method$http_if_modified_since$http_if_none_match$host$request_uri";
# fastcgi_pass_header "X-Accel-Expires";
# set $no_cache 0;
# fastcgi_cache pubcache;
# fastcgi_cache_valid 200 301 302 304 5m;
# fastcgi_cache_key "$request_method|$http_if_modified_since|$http_if_none_match|$host|$request_uri";
# fastcgi_cache_use_stale updating error timeout invalid_header http_500;
# fastcgi_pass_header Set-Cookie;
# fastcgi_pass_header Cookie;
# fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
# fastcgi_cache_bypass $no_cache;
# fastcgi_no_cache $no_cache;
# proxy_cache_purge PURGE from 127.0.0.1,192.168.118.10;
# fastcgi_pass 127.0.0.1:9000;
## fastcgi_pass unix:/var/run/php-fpm.sock;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# fastcgi_param HTTP_IF_NONE_MATCH $http_if_none_match;
# fastcgi_param HTTP_IF_MODIFIED_SINCE $http_if_modified_since;
# fastcgi_param HTTP_X_REAL_IP $remote_addr;
# include fastcgi_params;
#}
}
ssl.conf
#
# HTTPS server configuration
#
server {
listen 443 ssl http2 default_server;
# listen [::]:443 ssl;
server_name www.hostname.example;
root /path/to/root;
index index.php index.html;
#
# ssl_certificate hostname.example.crt;
# ssl_certificate_key hostname.example.key;
ssl_certificate hostname_example.crt;
ssl_certificate_key hostname_example.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
#
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
location ~ \.php$ {
fastcgi_cache portalName;
fastcgi_cache_valid 200 301 302 304 60m;
fastcgi_cache_key "$request_method$http_if_modified_since$http_if_none_match$host$request_uri";
fastcgi_pass_header "X-Accel-Expires";
# set $no_cache 0;
# fastcgi_cache pubcache;
# fastcgi_cache_valid 200 301 302 304 5m;
# fastcgi_cache_key "$request_method|$http_if_modified_since|$http_if_none_match|$host|$request_uri";
# fastcgi_cache_use_stale updating error timeout invalid_header http_500;
# fastcgi_pass_header Set-Cookie;
# fastcgi_pass_header Cookie;
# fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
# fastcgi_cache_bypass $no_cache;
# fastcgi_no_cache $no_cache;
# proxy_cache_purge PURGE from 127.0.0.1,192.168.118.10;
fastcgi_pass 127.0.0.1:9000;
# fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTP_IF_NONE_MATCH $http_if_none_match;
fastcgi_param HTTP_IF_MODIFIED_SINCE $http_if_modified_since;
fastcgi_param HTTP_X_REAL_IP $remote_addr;
include fastcgi_params;
}
}
UPD_2。好吧,谢谢大家的cmets。我去别处寻找问题的根源。
【问题讨论】:
-
你的 nginx 配置是什么样的?您是否在整个代码库中搜索了
443或一些寻找或包含 proto 的重定向? -
Somwhere,有些东西正在强制重定向到该端口,所以请按照 Lawrence 所说的做,并完整搜索
443 -
@LawrenceCherone 我添加了配置文件。在代码库中有一段js代码,乍一看基本上说选择端口80,否则选择443(但同样,这与之前编写代码的开发人员相矛盾,所以我可能会误会这段代码的实际作用...)