Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Shells Virtual Desktop
BMail.ag - Secure Email Service
Server.net
CPLicense.net
VPS Server
Buy VPN
Vultr
VMs for AI
HostDare
ReliableSite White-Label Dedicated Hosting for Resellers
InterServer VPS
BMail.ag - Secure Email Service
Best VPN
High-Performance Bare Metal Server Solutions
Karvl.com
Server Mania Cloud Hosting
DataWagon Hosting
AlphaVPS Hosting
Evoxt.com
Clouvider
VPS Hosting with NVMe
Residential IPs in the US & 4G Mobile Proxies in EU & US with Unlimited Bandwidth
ReliableSite White-Label Dedicated Hosting for Resellers
Rabisu - Hosting Solutions
Shells Virtual Desktop
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Need Help in Nginx Rewrite Rule

mca295188mca295188 Member

Hello There,

I need some help in creating rewrite rule for Nginx

Currently i am running Nginx as front end proxy for Apache...

I want to create rewrite rule in nginx..

for example i want http://domain-name/client should open http://domain-name/directory/sub-directory/index.html

please help..

Comments

  • RalliasRallias Member

    rewrite ^/client$ /directory/sub-directory/index.html;

  • @Rallias Thanks, i just have to edit this line and should place this in nginx server block na...

  • RalliasRallias Member

    mca295188 said: @Rallias Thanks, i just have to edit this line and should place this in nginx server block na...

    Tis the name of the game.

  • mca295188mca295188 Member
    edited May 2014

    @Rallias

    Please check this...

    server {
    listen 80;
    server_name localhost;
    rewrite ^/client$ /var/www/iptv/c/index.html;

    location / {
        proxy_pass http://127.0.0.1:8901/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
    
    location ~* \.(htm|html|jpeg|jpg|gif|png|css|js)$ {
        root /var/www;
        expires 30d;
    }
    

    }

    its not working...

  • tdc_admtdc_adm Member
    edited May 2014

    I think the rewrite rule by @Rallias is correct. You have applied the rule incorrectly because "/directory/sub-directory/index.html" does not include root directory but inside root directory instead. That means "rewrite ^/client$ /var/www/iptv/c/index.html;" has to be changed to "rewrite ^/client$ /iptv/c/index.html;" The root directory "/var/www" has to be excluded.

  • @Rallias ,@tdc_adm

    Here is my working config:-

    server {
    listen 80;
    server_name localhost;
    root /var/www;
    rewrite ^/client$ /iptv/c;

    location / {
    
        proxy_pass http://127.0.0.1:8901/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
    
    location ~* \.(htm|html|jpeg|jpg|gif|png|css|js)$ {
    
        expires 30d;
    }
    

    }

    but now when i access http://ip/client then link in browser is automatically converted to http://ip:8901/iptv/c

  • tdc_admtdc_adm Member
    edited May 2014

    Give this a try:
    `

    server {
    listen 80;
    server_name localhost;
    root /var/www;
    index index.php index.html index.htm;

    rewrite ^/client$ /iptv/c;
    rewrite ^/client(/.*) /iptv/c$1;
    
    location / {
        proxy_pass http://127.0.0.1:8901/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
    
    location ~* \.(htm|html|jpeg|jpg|gif|png|css|js)$ {
        expires 30d;
    }
    

    }

    `
    Also clear your browser cache then restart it.

  • @tdc_adm

    URL in browser is still being changed.

Sign In or Register to comment.