锐单电子商城 , 一站式电子元器件采购平台!
  • 电话:400-990-0325

【Web服务器端程序设计1】VSCode远程连接服务器配置Nginx虚拟主机和SSL证书

时间:2023-07-30 13:37:19 header11连接器

  • 综合开发环境:
    Visual Studio Code
  • 版本:
    Windows x64 1.64.0
  • 插件:
    中文(简体)语言包
    Remote Development
  • 服务器:
    阿里云轻量应用服务器
  • 操作系统:
    WordPress 5.6.2

一、VSCode远程连接服务器
1.使用服务器控制台远程连接服务器,将服务器切换到控制台root账号,输入passwd设置密码。
2、使用VSCode打开远程窗口,打开SSH配置文件(Open SSH Configuration File…),修改如下:保存后的连接Host(Connect to Host…),输入密码。如果服务器重置系统,则需要在本地删除C:/Users/sciuridae/.ssh/known_hosts文件。

#Host名 Host sciuridae  #IP地址  HostName 121.41.11.127  #用户名  User root 

二、配置Nginx虚拟主机和ssl证书
1、在usr/local/nginx/conf/vhost新建虚拟主机配置文件(sciuridae.conf)如下。如需使用HTTPS,将SSL证书安装到/usr/local/nginx/conf/ssl

server{ 
            listen 80 default;     listen [::]:80 default;     #HTTPS     listen 443 ssl http2 default;     listen [::]:443 ssl http2 default;     ssl_certificate /usr/local/nginx/conf/ssl/sciuridae.xyz.pem;     ssl_certificate_key /usr/local/nginx/conf/ssl/sciuridae.xyz.key;     ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;     ssl_ciphers TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH CHACHA20:EECDH AES128:RSA AES128:EECDH AES256:RSA AES256:EECDH 3DES:RSA 3DES:!MD5;     ssl_prefer_server_ciphers on;     ssl_session_timeout 10m;     ssl_session_cache builtin:1000 shared:SSL:10m;     ssl_buffer_size 1400;     add_header Strict-Transport-Security max-age=15768000;     ssl_stapling on;     ssl_stapling_verify on;     #服务名     server_name www.sciuridae.xyz;     #根目录路径     root /data/wwwroot/sciuridae;     #if ($ssl_protocol = "") { return 301 https://$host$request_uri; }     #if ($host != sciuridae.xyz) { return 301 $scheme://sciuridae.xyz$request_uri; }     #301重定向     if ($host = sciuridae.xyz){ 
                return 301 https://www.sciuridae.xyz$request_uri;     }     include /usr/local/nginx/conf/rewrite/sciuridae.conf; }

2、在usr/local/nginx/conf/rewrite新建配置文件(sciuridae.conf)如下。

#访问日志
access_log /data/wwwlogs/access_nginx.log combined;
#主页文件名
index index.html index.htm index.php;
#error_page 404 /404.html;
#error_page 502 /502.html;
#字符编码
charset utf-8;
location /nginx_status{ 
       
    stub_status on;
    access_log off;
    allow 127.0.0.1;
    deny all;
}
location ~ [^/]\.php(/|$) { 
       
    #fastcgi_pass remote_php_ip:9000;
    fastcgi_pass unix:/dev/shm/php-cgi.sock;
    fastcgi_index index.php;
    include fastcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ { 
       
    expires 30d;
    access_log off;
}
location ~ .*\.(js|css)?$ { 
       
    expires 7d;
    access_log off;
}
    location ~ ^/(\.user.ini|\.ht|\.git|\.svn|\.project|LICENSE|README.md) { 
       
    deny all;
}

3、在根目录路径/data/wwwroot/sciuridae部署Web项目文件。若文件过大可使用scp -r命令传输文件。
4、在终端输入/usr/local/nginx/sbin/nginx -s reload重启Nginx使配置生效。

锐单商城拥有海量元器件数据手册IC替代型号,打造电子元器件IC百科大全!

相关文章