Violetttte 2024-04-07 16:51 采纳率: 82.8%
浏览 23

nginx配置proxy_pass后https协议下网站404

user root;
#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       80;
        server_name  xxx.xxx.xxx.xx;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        root /www/dist;
        index index.html;

        #location / {
        #    root   /home/www/dist;
        #    index  index.html index.htm;
        #}
        #location / {
        #    try_files $uri $uri/ /index.html; #新的
        #}
        #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;
        }
        location / {
            try_files $uri $uri/ @router;#需要指向下面的@router否则会出现vue的路由在nginx中刷新出现404
            index  index.html index.htm;
        }
        location @router {
            rewrite ^.*$ /index.html last;
        }

        # 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
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    server {
        listen       443 ssl;
        server_name  xxx.xxx.xxx.xx;

        ssl_certificate /usr/local/nginx/conf/ssl/ipssl/zenon.crt;
        ssl_certificate_key /usr/local/nginx/conf/ssl/ipssl/zenon.key;

       # ssl_certificate      cert.pem;
       # ssl_certificate_key  cert.key;

        root /www/dist;
        index index.html;


        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

        location ^~ / {
            try_files $uri $uri/ @router;#需要指向下面的@router否则会出现vue的路由在nginx中刷新出现404
            index  index.html index.htm;
            proxy_pass http://xxx.xxx.xxx.xx:8081/;
            proxy_set_header Host $proxy_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
        }

        location @router {
            rewrite ^.*$ /index.html last;
        }
    }
}

这是我nginx配置的代码,我想做的是当前端以https协议被访问的时候,向后端发送的获取数据的协议都以http形式发送,(因为我的后端还没配置ssl证书)。但是出现的情况是不管下面这部分怎么配置,以https形式访问前端的时候都出现404报错 ,http协议下的网站则可以正常访问,请问是哪部分可能出现问题?

proxy_pass http://xxx.xxx.xxx.xx:8081/;
proxy_set_header Host $proxy_host;
  • 写回答

5条回答 默认 最新

  • rundreamsFly 2024-04-07 17:35
    关注

    看你方便远程不,或者如果是云服务器 可以帮忙调试下。

    评论

报告相同问题?

问题事件

  • 创建了问题 4月7日

悬赏问题

  • ¥15 ecology9的待办推送外部系统
  • ¥15 Mplus跑出来的数据只有原数据的一半
  • ¥15 vue项目添加全局处理解决一些开发问题
  • ¥40 微信小程序前后端交互
  • ¥15 linux安装依赖问题
  • ¥50 数据预处理(大量数据)
  • ¥15 多设备数据融合可视化显示控制
  • ¥15 公众号关键词自动回复超链接
  • ¥18 help me! 希望大家来看看 吉~
  • ¥15 C++显示超限兔子集结