我们先在server里面打上88的端口号,
然后start nginx启动监听一个服务88,让index.html的网页能在本地以:localhost:88,运行出这个网页,
此时如果你的域名是:http://www.xxx.com的话,你就可以用http://www.xxx.com:88在外部访问这个网页。
此时,你想把http://www.xxx.com,变成https://www.xxx.com的话,那么就跟着我往下走。
第一步:
我们想把腾讯云或者阿里云购买ssl证书后,只需要取这两个,
然后在下面再建立一个server,里面把如下图的信息打上,其中listen里面的80你可以换成你想要的任意端口,proxy_pass:这里右边填的是你监听的启动服务的端口,也就是我这里图一里面的那个端口,然后这里的listen 80 ssl 是填你在外网要访问的端口。
最后用nginx -t 如果显示的是这样说明成功了:
最后你就可以在外网用https访问了,
最后结果如下:
在互联网变https了,
最后附上整体代码:
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 88;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
# HTTPS server
#
server {
listen 80 ssl;
server_name www.hahaha.top;
ssl_certificate hahaha.top_bundle.pem;
ssl_certificate_key hahaha.top.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
# root E:\\transcalpfront;
# index index.html index.htm index.php;
proxy_pass http://hahaha.top:88; # spring boot 项目的端口号
# 固定写法-------------
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;
}
}
}