
1 yuxuan 2017-10-25 16:53:24 +08:00 server { listen 443; server_name yoursite.com; index index.html index.htm index.php default.html default.htm default.php; include none.conf; #error_page 404 /404.html; include enable-php.conf; location ~ /* { proxy_pass http://127.0.0.1:3333; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 12h; } location ~ /\. { deny all; } access_log off; } 我 nginx 这么配的 |
2 edison111cry OP @yuxuan 这样改的话可以实现 https:可以 访问 NODE.JS 的 3000 应用了,但是这样就访问不了 80 端口里的 index.html 内容了。 所以这个 HTTPS 能不能像 HTTP 实现以下两种: http :访问的是 80 端口的 index.html http:3000 : 访问的是 3000 端口的 node.js |
3 hzw758 2017-10-25 17:06:45 +08:00 类似问题我挣扎过很久,建议你把 nodejs 挂在二级域名上,一切都解决了 |
4 edison111cry OP @hzw758 嗯,是的,挂在二级域名可以搞定的。 然后想问一下这种情况 https 没办法像 http 那样通过增加一个端口号就可以访问到 80 又可以访问到 3000 端口是吧? |
5 Lentin 2017-10-25 17:13:41 +08:00 可以试试这个东西 https://caddyserver.com |
6 ysc3839 2017-10-25 17:16:10 +08:00 via Android 你的意思是 HTTP 和 HTTPS 两种协议共用一个端口吗?这个是可以实现,但 nginx 似乎不行。 不过 nginx 能做到这样的效果:在 3000 开 https,然后用 http://host:3000 访问的时候自动跳转为 https://host:3000 |
7 noe132 2017-10-25 17:18:46 +08:00 via Android 没太看懂你的意思。。。 你是说需要在 80 监听 nginx http 443 监听 nginx https 3000 监听 node http 和 https 么? |
8 edison111cry OP @ysc3839 不是,我想问一下 https 是不是可以像 http 那样通过区分端口号来访问不同的应用。 比如 http:80 这个访问的是 php,http:3000 这个访问的是 node.js 那么 https 能这样吗? |
9 edison111cry OP @noe132 不是,我想问一下 https 是不是可以像 http 那样通过区分端口号来访问不同的应用。 比如 http:80 这个访问的是 php,http:3000 这个访问的是 node.js 那么 https 能这样吗? |
10 noe132 2017-10-25 17:32:50 +08:00 via Android @edison111cry 肯定是可以的。而且这不关 https 的事,任何协议都可以监听任何端口(理论上) 如果是光监听 http 很简单,1 是 node 直接监听 3000 端口,2 或者 node 监听一个本地端口,然后用 nginx 反代。 https 的话多一个证书配置。在 nginx 配证书的话就在 conf 里添加一个 server,使用 nginx 配置的证书,反代到 node 的 http 端口上。或者是 node 编写配置 https 服务端。 如果需要在 300 )配置 http 和 https,在 nginx 配置两个监听 3000 的 server 就行了。如果需要 http 跳转 https,就配一条 rewrite 即可。如果是用 node 的话那就得看 node 的 https 客户端怎么配置了 |
11 6IbA2bj5ip3tK49j 2017-10-25 18:17:36 +08:00 http,https 和端口没啥关系,只要你愿意,可以用 80 开 https,443 开 http。 |
12 yuxuan 2017-10-25 18:21:38 +08:00 @edison111cry 回答完就忘记这茬了 https 再去访问端口 这个还真没注意过 我自己是挂的 2 级域名 |
13 6IbA2bj5ip3tK49j 2017-10-25 18:23:12 +08:00 看了下,你希望 http://a.com:80 nginx 301-> https://a.com:443 https://a.com:443 nginx http://a.com:3000 node https://a.com:3000 nginx 很简单啊。node 去监听 4000 http://a.com:3000 nginx 301->https://a.com:3000 https://a.com:3000 nginx 反代 4000 |
14 Tink PRO 没问题 |
15 edison111cry OP @xgfan 大神,您的就是我想要达成的效果。但是我还是有一点不知道咋配置, 我现在的 nginx.conf 文件里, server { listen 80; rewrite ^(.*)$ https://$host$1 permanent; } server { listen 443 ssl; server_name localhost; } 现在访问 http://a.com:80 可以实现跳转到 https://a.com 但是 http://a.com:3000 现在访问不了了,没有配置 HTTPS 前是可以访问到 NODE 程序的 所以我怎么样配置才能 http://a.com:3000 也跳转到 https://a.com:3000 ( 很简单啊。node 去监听 4000 http://a.com:3000 nginx 301->https://a.com:3000 https://a.com:3000 nginx 反代 4000 ) 您写的这段没能太明白,node 监听的是 3000,还要再去监听 4000 ? |
16 xfspace 2017-10-25 20:58:58 +08:00 via Android server { listen 3000 ssl; } |
17 edison111cry OP @xfspace 第一次用 HTTPS,我还以为 HTTPS 只能监听 443 呢。 刚监听 3000 端口成功了,但是 https:/a.com:3000 却显示的是 80 端口的程序服务,怎么配置能让它显示 NODE 的 3000 程序 |
18 Marfal 2017-10-25 21:12:22 +08:00 @edison111cry 求求你发个完整的配置吧 |
19 edison111cry OP http { server { listen 80; server_name localhost; location / { root html; index index.php index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } rewrite ^(.*)$ https://$host$1 permanent; location ~ \.php/?.*$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; set $fastcgi_script_name2 $fastcgi_script_name; if ($fastcgi_script_name ~ "^(.+\.php)(/.+)$") { set $fastcgi_script_name2 $1; set $path_info $2; } fastcgi_param PATH_INFO $path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name2; fastcgi_param SCRIPT_NAME $fastcgi_script_name2; } } server { listen 443 ssl; server_name localhost; ssl_certificate cert/214291770900892.pem; ssl_certificate_key cert/214291770900892.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_prefer_server_ciphers on; location / { root html; index index.php index.html index.htm; } location ~ \.php/?.*$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; set $fastcgi_script_name2 $fastcgi_script_name; if ($fastcgi_script_name ~ "^(.+\.php)(/.+)$") { set $fastcgi_script_name2 $1; set $path_info $2; } fastcgi_param PATH_INFO $path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name2; fastcgi_param SCRIPT_NAME $fastcgi_script_name2; } } # nginx listen on port 3000 with https server { listen 3000 ssl; server_name localhost:3000; ssl_certificate cert/214291770900892.pem; ssl_certificate_key cert/214291770900892.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; #ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; } } |
20 edison111cry OP |
21 Marfal 2017-10-25 22:31:27 +08:00 |
22 xfspace 2017-10-26 00:03:05 +08:00 via Android @edison111cry 用 proxy_pass ? |
23 ysc3839 2017-10-26 03:01:10 +08:00 via Android @edison111cry 肯定可以的,https 又不强制 443 端口,你可以在 3000 端口上开 https。 |
24 paranoiagu 2017-10-26 08:20:19 +08:00 via Android 3000 端口既是 http,又是 https,这怎么搞? |
25 ysc3839 2017-10-26 08:28:59 +08:00 via Android @paranoiagu 我不确定 nginx 能否实现。不过我前面说了,nginx 能实现一个类似的效果:在 3000 开 https,然后用 http//host:3000 访问的时候自动跳转为 https//host:3000 |
26 msg7086 2017-10-26 09:39:56 +08:00 你这例子前后完全是两回事啊。 你 nginx 上是访问 http 80 端口自动跳转到 https 443 端口。 这是两个不同的服务跑在两个不同的端口上。 一个是 80,一个是 443。 现在你要 3000 端口既做 http 又做 https,这难度跟之前的可不是一个级别。 |
27 edison111cry OP @msg7086 经过大家的回复,我意识到自已之前的理解有一定问题了。 之前访问 http:/a.com:80 或者 http:/a.com 可以访问到 index.html 程序。 访问 http:/a.com:3000 可以访问到 node.js 程序。 然后我布薯了 HTTPS,让 HTTP 链接转为 HTTPS,80 端口没有问题,但是 3000 端口访问不到 |
28 msg7086 2017-10-26 11:37:53 +08:00 80 端口部署 https 的话,是部署在 443 上,不是 80 上的。 |
29 msg7086 2017-10-26 11:39:28 +08:00 也就是说,首先你要为你 nodejs 指定一个新的端口给 https 服务才好。 |
30 openDatabase 2019-04-01 16:18:45 +08:00 @edison111cry 现在怎么样了 问题解决了吗 我也遇到了同样的问题,现在网站访问使用 https http 访问会从重写成 https,还有一个链接是通过 8081 才能访问的 怎么让 8081 的访问也启动 https |