简体   繁体   English

Apache2:将url重写为localhost上的其他端口

[英]Apache2: Rewrite url to different port on localhost

There is a service on my local computer available on 127.0.0.1:8080 , but I would prefer to use it rather like 127.0.0.1/qwerty/ 我的本地计算机上有一项服务可以在127.0.0.1:8080 ,但是我更喜欢使用它,而不是127.0.0.1/qwerty/

I tried to add in /etc/apache2/sites-available/default : 我试图添加/ etc / apache2 / sites-available / default

RewriteEngine on
RewriteRule (qwerty/.*)$ http://127.0.0.1:8080/$1 

Before that I symlinked rewrite.load in mods-enabled and restarted apache2 server. 在此之前,我在启用了mods的apache2服务器中重新链接了rewrite.load。

Unfortunately, it doesn't work. 不幸的是,它不起作用。


Edit: To be more specific - This service is calibre-server and its output is on port 8080 , while on port 80 works apache2. 编辑:更具体地说-该服务是calibre-server,其输出在端口8080 ,而在端口80运行apache2。 Then I'd like to do the same with my flask (python micro framework) project (it works on port 5000 ). 然后,我想对我的flask(python micro framework)项目(在port 5000 )执行相同的操作。


Edit 2: I used reversed proxy trick from link , typing calibre-server --url-prefix /calibre in command line and it works ( without proxying anything i needed to set proxy in /etc/apache2/sites-available/default ). 编辑2:我从链接中使用了反向代理技巧,在命令行中输入calibre-server --url-prefix /calibre ,它可以正常工作( 无需代理我需要在/ etc / apache2 / sites-available / default中设置代理的任何内容 )。

What does not work is this flask thing. 这瓶东西不起作用。

I will write down everything I did, because I'm not sure I understood correctly. 我会记下我所做的一切,因为我不确定我是否正确理解。 @Ωmega : I do start flask project by typing python demo.py in demo directory. @Ωmega:我通过在demo目录中键入python demo.py来启动flask项目。 I created .htaccess file in this directory and put there the line you've suggested and it didn't work, so I changed all file content to: 我在此目录中创建了.htaccess文件,并在其中输入了您建议的行,但该行不起作用,因此我将所有文件内容更改为:

Options FollowSymLinks
RewriteEngine On
RewriteRule ^$ http://127.0.0.1/flask/ [R=301,L]

but it still doesn't work. 但它仍然不起作用。

在提供http://127.0.0.1:8080 目录的设置中,执行以下重定向:

RewriteRule ^$ http://127.0.0.1/qwerty/ [R=301,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM