升级https后使用Nginx把之前URL反代理

/ 分享 / 无站内评论 / 363浏览

背景:

博客绑定很多域名,如 sansani.club isan.site sani.site 139.199.230.183,在保存文章时,文章内的资源路径就会以当前域名进行保存,后面升级https后,之前的http路径将不再支持访问,为了解决资源失效问题,使用Nginx进行反向代理解决。

代码:

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/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  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;


//将http://isan.site sani.site 139.199.230.183重定向到https://www.sansani.club
 server {
    listen 80;
    server_name isan.site sani.site 139.199.230.183;
    return 301 https://www.sansani.club$request_uri;
        }
//就https://sansani.club isan.site sani.site 139.199.230.183重定向到https://www.sansani.club
server {
    listen 443 ssl;
    ssl_certificate /usr/share/nginx/conf/1_www.sansani.club_bundle.crt;
    ssl_certificate_key /usr/share/nginx/conf/2_www.sansani.club.key;
    server_name sansani.club isan.site sani.site 139.199.230.183;
    return 301 https://www.sansani.club$request_uri;
        }
//将https://www.sansani.club重定向到服务器上面的本地项目
server {
    listen 443 ssl;
    ssl_certificate /usr/share/nginx/conf/1_www.sansani.club_bundle.crt;
    ssl_certificate_key /usr/share/nginx/conf/2_www.sansani.club.key;
    server_name  www.sansani.club;

        location / {

            #root   html;
            #index  index.html index.htm;
            proxy_pass http://127.0.0.1:88;

        }
        }


}

nginx常用命令:

验证配置是否正确: nginx -t

 

查看Nginx的版本号:nginx -V

 

启动Nginx:start nginx

 

快速停止或关闭Nginx:nginx -s stop

 

正常停止或关闭Nginx:nginx -s quit

 

配置文件修改重装载命令:nginx -s reload
召唤蕾姆
琼ICP备18000156号

鄂公网安备 42011502000211号