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

niyazi.toros at niyazi.toros at
Thu Jun 13 10:33:36 UTC 2019



I have a small projects. I have a domain as I install nginx using stable ubuntu commands.

When I type or http:// 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://********


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

*	http://   to its a dart server and it is in same machine as nginx.


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


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



*	http:// redirect to



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


server {

    charset UTF-8;

    listen 80 ;

    listen [::]:80 ;



    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

    location /myrestapiA {

        proxy_set_header X-Forwarded-For $remote_addr;

        proxy_set_header Host $http_host;

        proxy_pass "";



    location / myrestapiB{

        proxy_set_header X-Forwarded-For $remote_addr;

        proxy_set_header Host $http_host;

        proxy_pass "";



    # 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;





Niyazi Toros

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the nginx mailing list