Nginx配置-https可以使用但不能使用http

时间:2019-04-02 08:13:43

标签: nginx debian

我在Debian 9上重新配置了Nginx设置时遇到问题。 使用https可以很好地加载我的网站,但是使用http访问它时却得到404 Not Found。

我尝试删除ssl证书,但是它可以工作,但是我需要在https和/ ping中使用/ webex / receive和在http中使用/ mailgun位置。 请参阅我编辑后的服务器块:

server {

    listen 80;
    listen 443 ssl;
    include snippets/self-signed.conf;
    include snippets/ssl-params.conf;

   location /ping {
        proxy_pass http://xx.xx.xx.xxx:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

    location /mailgun {
        proxy_pass http://xx.xx.xx.xxx:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

    location /webex/receive {
        proxy_pass http://xx.xx.xx.xxx:8080;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

}

所有位置(/ ping,/ mailgun和/ webex / receive)都在https中工作,但我只希望/ webex / receive在https中,其他位置/ mailgun和/ ping在http中。

1 个答案:

答案 0 :(得分:0)

我找到了解决方法

server {
    listen 80;
    listen [::]:80;

        root /var/www/xx.xx.xx.xxx/html;
        index index.html index.htm index.nginx-debian.html;

        server_name xx.xx.xx.xxx www.xx.xx.xx.xxx;

        location / {
                try_files $uri $uri/ =404;
        }

        location /ping {
                 proxy_pass http://xx.xx.xx.xxx:3000;
        }
        location /mailgun {
                 proxy_pass http://xx.xx.xx.xxx:3000;
        }
}

server {
    listen 443 ssl;
    include snippets/self-signed.conf;
    include snippets/ssl-params.conf;

        location /webex/receive {
             proxy_pass http://xx.xx.xx.xxx:8080;
        }

}