该配置为实现某特殊功能

1.安装nginx:
Centos:
yum install -y epel-release && yum install -y nginx
Ubuntu:
sudo apt-get update && sudo apt-get install nginx


2.修改配置
修改/etc/nginx/conf.d/目录下的default.conf,如果没有则新建一个。将内容修改为(修改之后请将注释删除):

server {

    listen 80;
    server_name xxxxx; #你的域名

    rewrite ^(.*) https://$server_name$1 permanent;
}

server {
    listen       443 ssl http2;
    server_name xxxxx;#你的域名
 
    charset utf-8;


    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384;
    ssl_ecdh_curve secp384r1;
    ssl_prefer_server_ciphers on;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 10m;
    ssl_session_tickets off;
    ssl_certificate /xxx/xxx/xxx.crt;#域名证书路径
 
    ssl_certificate_key /xxx/xxx/xxx.key;#域名证书密钥路径
 


location /xxx { #xxx为path值

      proxy_redirect off;
      proxy_pass http://127.0.0.1:65432;#该端口为你的配置端口
 
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
      proxy_set_header Host $host;
      # Show real IP in v2ray access.log
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}


    access_log  /var/log/nginx/xxxx.access.log;
    error_log /var/log/nginx/xxx.error.log;

root /etc/nginx/html;#你的网页内容路径,可自己上传内容
 
    location / {
        index  index.html;
    }    
}

3.查看配置是否成功
保存好default.conf之后使用命令nginx -t查看是否成功,若提示以下内容即为成功。

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful`

4.重启nginx
systemctl restart nginx
在浏览器输入你的域名应该能看到https访问的你上传的网页内容了。

Last modification:March 18th, 2020 at 07:54 pm
如果觉得我的文章对你有用,请随意赞赏或点击页内广告。