Welcome! Log In Create A New Profile

Advanced

How can I use proxy_pass and how can I redirect rest of it to default index . html

June 13, 2019 06:34AM
Hi,



I have a small projects. I have a domain as mob.ntms.com. I install nginx using https://nginx.org/en/linux_packages.html stable ubuntu commands.

When I type 127.0.0.1 or http:// mob.ntms.com I can see nginx default index.html.



First I change the default index.html and place my own. My html uses some asstes and images so in /user/shared/nginx/html folder I move this 2 folder (asstest and images).

Till this everything works as I expected. Now I am in difficult part. Let me try to explain before I can paste my code:



I have a tcp socket in my local network which I connect remotly like if I type:



* http:// mob.ntms.com/myrestapi/********



The /myrestapi/ is the where my api is reside. The ******* its dynamic. I need to redirect

* http:// mob.ntms.com/myrestapi/ to 127.0.0.1:1024



127.0.0.1:1024 its a dart server and it is in same machine as nginx.



If I type other than this (http:// mob.ntms.com/myrestapi/ ) all the request including 404 must be redirect them to nginx default index.html.



* http:// mob.ntms.com redirect to default index.html
* http:// mob.ntms.com/<dynamic> redirect to default index.html



Only;

* http:// mob.ntms.com/myrestapi redirect to 127.0.0.1:1024





Currently my conf.d/default.conf look like this:



server {

charset UTF-8;

listen 80 ;

listen [::]:80 ;



server_name mob.ntms.com;

access_log /var/log/nginx/host.access.log main;



location / {

root /usr/share/nginx/html;

index index.html index.htm;

}





# define error page

error_page 404 = @notfound;



# error page location redirect 301

location @notfound {

return 302 /;

}



# error_page 404 =200 /index.html;

# error_page 404 /usr/share/nginx/html/index.html;



# redirect server error pages to the static page /50x.html

#

error_page 500 502 503 504 /index.html;

location = / {

root /usr/share/nginx/html;

}



# proxy the PHP scripts to Apache listening on 127.0.0.1:1024

location /myrestapiA {

proxy_set_header X-Forwarded-For $remote_addr;

proxy_set_header Host $http_host;

proxy_pass "http://127.0.0.1:1024/";

}



location / myrestapiB{

proxy_set_header X-Forwarded-For $remote_addr;

proxy_set_header Host $http_host;

proxy_pass "http://127.0.0.1:1024/";

}



# deny access to .htaccess files, if Apache's document root

# concurs with nginx's one

location ~ /\.ht {

deny all;

}



location = /nginx.conf {

deny all;

}



# Deny access to hidden files (beginning with a period)

location ~ /\. {

deny all;

}

}



Thanks

Niyazi Toros

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

How can I use proxy_pass and how can I redirect rest of it to default index . html

Niyazi June 13, 2019 06:34AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 127
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready