众所周知

家里的服务器在外网通过80端口和443端口访问。

所以在之前的vm实例上做了给Nginx反向代理。

具体实现比较简单...

首先在服务器上安装Nginx。

之前是CentOS,执行以下命令即可

yum install nginx

接下来简单配置

nano /etc/nginx/nginx.conf

修改80端口和443端口部分

server {
listen       80;
server_name  ******;                                    #对应你的域名
        location /
         {
        proxy_set_header Host $host;
        proxy_set_header X-Real-Ip $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_pass http://******/;                       #对应你家里的..
          }
      }
server {
    listen       443 ;#ssl http2 default_server;
    server_name  ******; #对应域名

#    access_log  logs/quancha.access.log  main;
#    error_log  logs/quancha.error.log;
    #root   html;
    #index  login_page.php  index.html index.htm index.php;


    ## send request back to apache ##
    ssl                  on;
    ssl_certificate      ******; #对应证书
    ssl_certificate_key  ******; #对应key


    ssl_session_timeout  5m;
    ssl_protocols  SSLv2 SSLv3 TLSv1.2;
    #ssl_ciphers  HIGH:!aNULL:!MD5;
    ssl_ciphers     ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256:AES128-SHA:AES256-SHA:RC4-SHA:DES-CBC3-SHA:RC4-MD5;
    ssl_prefer_server_ciphers   on;


    location / {
        #Proxy Settings
        proxy_redirect     off;
        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_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
        #proxy_max_temp_file_size 0;
        proxy_connect_timeout      90;
        proxy_send_timeout         90;
        proxy_read_timeout         90;
        #proxy_buffer_size          4k;
        #proxy_buffers              4 32k;
        #proxy_busy_buffers_size    64k;
        #proxy_temp_file_write_size 64k;
        proxy_pass  ******; #你家...
        break;
   }
}

配置开机启动

cd /lib/systemd/system/
nano nginx.service
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
# Nginx will fail to start if /run/nginx.pid already exists but has the wrong
# SELinux context. This might happen when running `nginx -t` from the cmdline.
# https://bugzilla.redhat.com/show_bug.cgi?id=1268621
ExecStartPre=/usr/bin/rm -f /run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true
systemctl enable nginx.service   #开机启动
systemctl start nginx.service    #启动
systemctl stop nginx.service     #停止
systemctl restart nginx.service  #重启

就这样