Nginx URL屏蔽到另一个域

时间:2017-09-08 16:16:16

标签: nginx url-rewriting

我刚在我的VPS上安装了Nginx作为VestaCP的一项功能。

我尝试做的是将网址http://example.com屏蔽为http://12345.com,因此当用户访问http://example.com/path/file.mp4时,他们会看到http://12345.com/path/file.mp4的内容,但浏览器仍会显示网址http://example.com/path/file.mp4

我用Google搜索并找到了一个主题here。它看起来像我正在寻找的答案。但是当我将他的代码应用到nginx.conf时,VestaCP显示Error: nginx failed to start with new config并停止工作。

以下是代码:

server {
    listen 80;
    server_name sub.example.com;

    location / {
    proxy_pass https://123.12.12.12;
    rewrite ^/$ /path last;
    }
}

这对我来说是正确的解决方案吗?我对此完全陌生,所以我不知道我是否做得正确。

编辑:我能够使用apache .htaccess完成工作。如何将其转换为与Nginx一起使用?

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^ http://12345.com%{REQUEST_URI} [L,NE,P]

1 个答案:

答案 0 :(得分:0)

您只需要下面,不需要重写

server {
    listen 80;
    server_name sub.example.com;

    location / {
       proxy_pass https://123.12.12.12;
    }
}
相关问题