This topic created in 3376 days ago, the information mentioned may be changed or developed.
可能用了假的 nginx , default.conf.erb 写法
server {
root <%= ENV['OPENSHIFT_REPO_DIR'] %>/www;
listen <%= ENV['OPENSHIFT_PHP_IP'] %>:<%= ENV['OPENSHIFT_PHP_PORT'] %>;
server_name <%= ENV['OPENSHIFT_APP_DNS'] %>;
index index.php index.html index.htm <%= ENV['NGINX_EXTRA_INDEX'] %>;
set_real_ip_from <%= ENV['OPENSHIFT_PHP_IP'] %>;
real_ip_header X-Forwarded-For;
# Redirect all HTTP requests to HTTPS with a 301 Moved Permanently response.
if ($server_port = 80){
return 301 https://$server_name$request_uri;}
if ($scheme = http){
return 301 https://$server_name$request_uri;}
# avoid caching by proxies
add_header Cache-Control private;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:<%= ENV['OPENSHIFT_PHP_DIR'] %>/run/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
include openshift_params;
# uncomment to export all environment variables to fastcgi
#include <%= ENV['OPENSHIFT_REPO_DIR'] %>/config/nginx.d/export_env;
}
# avoid unnecessary log
location = /favicon.ico {
access_log off;
log_not_found off;
}
location = /robots.txt {
access_log off;
log_not_found off;
}
# Handle any other URI
location / {
try_files $uri $uri/ =404;
}
}
Supplement 1 · Feb 3, 2017
环境生成的 web 端口是 8080 ,再另加 server ssl 的话会 503 ,不管加不加 if 都会重定向循环
4 replies • 2017-03-06 10:31:21 +08:00
 |
|
1
lhbc Jan 30, 2017 via iPhone
不要用 if 不要用 if 不要用 if
http 和 https 分开两段 server {}
|
 |
|
2
php7 Feb 1, 2017 via Android
提楼上的
|
 |
|
3
edyuy Feb 24, 2017 1
OpenShift 的架构和一般的 VM 是不一样的,它的 https 由上一层的 nginx 所提供(所以你也发现了你的 nginx 配置里连证书和加密方式都不配置),所以在用户的应用层面拿到的都是 http 的请求(当然,也都是 80 端口的),其他答案那个方式也是不行的,因为你的应用并不会去监听 80 和 443 。正确的做法是,首先把你写的两段 if 替换为
if ($http_x_forwarded_proto != "https") { rewrite ^(.*)$ https://$server_name$1 permanent; }
使用上层 nginx 传来的客户端访问方式进行判断,其中 rewrite 改为 return 301 也是可以的
|
 |
|
4
jmhjhjhj Mar 6, 2017
@ edyuy 貌似并不好使,会提示 301 Moved Permanently ,然后循环就什么都没了,现在用 index 做 metahttp-equiv="refresh"勉强一下了
|