[prev in list] [next in list] [prev in thread] [next in thread] 

List:       nginx
Subject:    How can I use proxy_pass and how can I redirect rest of it to default index . html
From:       <niyazi.toros () gmail ! com>
Date:       2019-06-13 10:33:36
Message-ID: 000001d521d3$76087720$62196560$ () gmail ! com
[Download RAW message or body]

This is a multipart message in MIME format.

[Attachment #2 (multipart/alternative)]
This is a multipart message in MIME format.


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


[Attachment #5 (text/html)]

<html xmlns:v="urn:schemas-microsoft-com:vml" \
xmlns:o="urn:schemas-microsoft-com:office:office" \
xmlns:w="urn:schemas-microsoft-com:office:word" \
xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" \
xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type \
content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 \
(filtered medium)"><style><!-- /* Font Definitions */
@font-face
	{font-family:Wingdings;
	panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
	{font-family:"Cambria Math";
	panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
	{font-family:"Yu Gothic";
	panose-1:2 11 4 0 0 0 0 0 0 0;}
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
	{font-family:"\@Yu Gothic";
	panose-1:2 11 4 0 0 0 0 0 0 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0cm;
	margin-bottom:.0001pt;
	font-size:11.0pt;
	font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:#0563C1;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{mso-style-priority:99;
	color:#954F72;
	text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
	{mso-style-priority:34;
	margin-top:0cm;
	margin-right:0cm;
	margin-bottom:0cm;
	margin-left:36.0pt;
	margin-bottom:.0001pt;
	font-size:11.0pt;
	font-family:"Calibri",sans-serif;}
span.EmailStyle17
	{mso-style-type:personal-compose;
	font-family:"Calibri",sans-serif;
	color:windowtext;}
.MsoChpDefault
	{mso-style-type:export-only;
	font-family:"Calibri",sans-serif;}
@page WordSection1
	{size:612.0pt 792.0pt;
	margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
	{page:WordSection1;}
/* List Definitions */
@list l0
	{mso-list-id:609706557;
	mso-list-type:hybrid;
	mso-list-template-ids:33870096 201326593 201326595 201326597 201326593 201326595 \
201326597 201326593 201326595 201326597;} @list l0:level1
	{mso-level-number-format:bullet;
	mso-level-text:;
	mso-level-tab-stop:none;
	mso-level-number-position:left;
	text-indent:-18.0pt;
	font-family:Symbol;}
@list l0:level2
	{mso-level-number-format:bullet;
	mso-level-text:o;
	mso-level-tab-stop:none;
	mso-level-number-position:left;
	text-indent:-18.0pt;
	font-family:"Courier New";}
@list l0:level3
	{mso-level-number-format:bullet;
	mso-level-text:;
	mso-level-tab-stop:none;
	mso-level-number-position:left;
	text-indent:-18.0pt;
	font-family:Wingdings;}
@list l0:level4
	{mso-level-number-format:bullet;
	mso-level-text:;
	mso-level-tab-stop:none;
	mso-level-number-position:left;
	text-indent:-18.0pt;
	font-family:Symbol;}
@list l0:level5
	{mso-level-number-format:bullet;
	mso-level-text:o;
	mso-level-tab-stop:none;
	mso-level-number-position:left;
	text-indent:-18.0pt;
	font-family:"Courier New";}
@list l0:level6
	{mso-level-number-format:bullet;
	mso-level-text:;
	mso-level-tab-stop:none;
	mso-level-number-position:left;
	text-indent:-18.0pt;
	font-family:Wingdings;}
@list l0:level7
	{mso-level-number-format:bullet;
	mso-level-text:;
	mso-level-tab-stop:none;
	mso-level-number-position:left;
	text-indent:-18.0pt;
	font-family:Symbol;}
@list l0:level8
	{mso-level-number-format:bullet;
	mso-level-text:o;
	mso-level-tab-stop:none;
	mso-level-number-position:left;
	text-indent:-18.0pt;
	font-family:"Courier New";}
@list l0:level9
	{mso-level-number-format:bullet;
	mso-level-text:;
	mso-level-tab-stop:none;
	mso-level-number-position:left;
	text-indent:-18.0pt;
	font-family:Wingdings;}
ol
	{margin-bottom:0cm;}
ul
	{margin-bottom:0cm;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=en-CY link="#0563C1" \
vlink="#954F72"><div class=WordSection1><p class=MsoNormal>Hi,<o:p></o:p></p><p \
class=MsoNormal><o:p>&nbsp;</o:p></p><p class=MsoNormal><span lang=TR>I have a small \
projects. I have a domain as mob.ntms.com. I install nginx using <a \
href="https://nginx.org/en/linux_packages.html">https://nginx.org/en/linux_packages.html</a> \
stable ubuntu commands.<o:p></o:p></span></p><p class=MsoNormal><span lang=TR>When I \
type 127.0.0.1 or http:// mob.ntms.com I can see nginx default index.html. \
<o:p></o:p></span></p><p class=MsoNormal><span lang=TR><o:p>&nbsp;</o:p></span></p><p \
class=MsoNormal><span lang=TR>First I change the default index.html and place my own. \
My html uses some asstes and images so in </span>/user/shared/nginx/html folder<span \
lang=TR> I move this 2 folder (asstest and images).<o:p></o:p></span></p><p \
class=MsoNormal><span lang=TR>Till this everything works as I expected. Now I am in \
difficult part. Let me try to explain before I can paste my \
code:<o:p></o:p></span></p><p class=MsoNormal><span \
lang=TR><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span lang=TR>I have a tcp \
socket in my local network which I connect remotly like if I \
type:<o:p></o:p></span></p><p class=MsoNormal><span \
lang=TR><o:p>&nbsp;</o:p></span></p><ul style='margin-top:0cm' type=disc><li \
class=MsoListParagraph style='margin-left:0cm;mso-list:l0 level1 lfo1'><span \
lang=TR>http:// mob.ntms.com/<span \
style='color:red'>myrestapi/********</span><o:p></o:p></span></li></ul><p \
class=MsoNormal><span lang=TR><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span \
lang=TR>The /myrestapi/ is the where my api is reside. The ******* its dynamic. I \
need to redirect <o:p></o:p></span></p><ul style='margin-top:0cm' type=disc><li \
class=MsoListParagraph style='margin-left:0cm;mso-list:l0 level1 lfo1'><span \
lang=TR>http:// mob.ntms.com/<span style='color:red'>myrestapi/     </span><span \
style='color:black'>to </span></span><span lang=TR style='color:black'>  \
</span>127.0.0.1:1024<span lang=TR><o:p></o:p></span></li></ul><p \
class=MsoNormal><span lang=TR><o:p>&nbsp;</o:p></span></p><p \
class=MsoNormal>127.0.0.1:1024<span lang=TR> its a dart server and it is in same \
machine as nginx.<o:p></o:p></span></p><p class=MsoNormal><span \
lang=TR><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span lang=TR>If I type other \
than this (<span style='color:red'>http:// mob.ntms.com/myrestapi/ </span><span \
style='color:black'>) all the request </span>including 404 must be redirect them to \
nginx default index.html.<o:p></o:p></span></p><p class=MsoNormal><span \
lang=TR><o:p>&nbsp;</o:p></span></p><ul style='margin-top:0cm' type=disc><li \
class=MsoListParagraph style='margin-left:0cm;mso-list:l0 level1 lfo1'><span lang=TR \
style='color:red'>http:// mob.ntms.com </span><b><span lang=TR \
style='color:black'>redirect to</span></b><span lang=TR style='color:black'> default \
index.html</span><span lang=TR><o:p></o:p></span></li><li class=MsoListParagraph \
style='margin-left:0cm;mso-list:l0 level1 lfo1'><span lang=TR \
style='color:red'>http:// mob.ntms.com/&lt;dynamic&gt; </span><b><span lang=TR \
style='color:black'>redirect to</span></b><span lang=TR style='color:black'> default \
index.html</span><span lang=TR><o:p></o:p></span></li></ul><p class=MsoNormal><span \
lang=TR><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span \
lang=TR>Only;<o:p></o:p></span></p><ul style='margin-top:0cm' type=disc><li \
class=MsoListParagraph style='margin-left:0cm;mso-list:l0 level1 lfo1'><span lang=TR \
style='color:red'>http:// mob.ntms.com/myrestapi </span><b><span lang=TR \
style='color:black'>redirect to</span></b><span lang=TR style='color:black'> \
</span>127.0.0.1:1024<span lang=TR><o:p></o:p></span></li></ul><p \
class=MsoNormal><span lang=TR><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span \
lang=TR><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><b><span lang=TR>Currently my \
conf.d/default.conf look like this:<o:p></o:p></span></b></p><p class=MsoNormal><span \
lang=TR><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span lang=TR>server \
{<o:p></o:p></span></p><p class=MsoNormal><span lang=TR>       charset \
UTF-8;<o:p></o:p></span></p><p class=MsoNormal><span lang=TR>       listen 80 \
;<o:p></o:p></span></p><p class=MsoNormal><span lang=TR>       listen [::]:80 \
;<o:p></o:p></span></p><p class=MsoNormal><span lang=TR>       \
<o:p></o:p></span></p><p class=MsoNormal><span lang=TR>        server_name \
<b>mob.ntms.com</b>;<o:p></o:p></span></p><p class=MsoNormal><span lang=TR>       \
access_log   /var/log/nginx/host.access.log   main;<o:p></o:p></span></p><p \
class=MsoNormal><span lang=TR><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span \
lang=TR>       location / {<o:p></o:p></span></p><p class=MsoNormal><span lang=TR>    \
root     /usr/share/nginx/html;<o:p></o:p></span></p><p class=MsoNormal><span \
lang=TR>               index   index.html <b>index.htm</b>;<o:p></o:p></span></p><p \
class=MsoNormal><span lang=TR>       }<o:p></o:p></span></p><p class=MsoNormal><span \
lang=TR><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span \
lang=TR><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span lang=TR>       # define \
error page<o:p></o:p></span></p><p class=MsoNormal><span lang=TR>       error_page \
404 = @notfound;<o:p></o:p></span></p><p class=MsoNormal><span \
lang=TR><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span lang=TR>       # error \
page location redirect 301<o:p></o:p></span></p><p class=MsoNormal><span lang=TR>     \
location @notfound {<o:p></o:p></span></p><p class=MsoNormal><span lang=TR>           \
return 302 /;<o:p></o:p></span></p><p class=MsoNormal><span lang=TR>       \
}<o:p></o:p></span></p><p class=MsoNormal><span \
lang=TR><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span lang=TR>#       \
error_page 404 =200 /index.html;<o:p></o:p></span></p><p class=MsoNormal><span \
lang=TR>#       error_page   404                           \
/usr/share/nginx/html/index.html;<o:p></o:p></span></p><p class=MsoNormal><span \
lang=TR><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span lang=TR>       # \
redirect server error pages to the static page /50x.html<o:p></o:p></span></p><p \
class=MsoNormal><span lang=TR>       #<o:p></o:p></span></p><p class=MsoNormal><span \
lang=TR>       error_page     500 502 503 504   /index.html;<o:p></o:p></span></p><p \
class=MsoNormal><span lang=TR>       location = / {<o:p></o:p></span></p><p \
class=MsoNormal><span lang=TR>               root     \
/usr/share/nginx/html;<o:p></o:p></span></p><p class=MsoNormal><span lang=TR>       \
}<o:p></o:p></span></p><p class=MsoNormal><span \
lang=TR><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span lang=TR>       # proxy \
the PHP scripts to Apache listening on 127.0.0.1:1024<o:p></o:p></span></p><p \
class=MsoNormal><span lang=TR>       <b>location /<span \
style='color:red'>myrestapiA</span></b><span style='color:red'> \
</span>{<o:p></o:p></span></p><p class=MsoNormal><span lang=TR>               \
proxy_set_header X-Forwarded-For $remote_addr;<o:p></o:p></span></p><p \
class=MsoNormal><span lang=TR>               proxy_set_header Host \
$http_host;<o:p></o:p></span></p><p class=MsoNormal><span lang=TR>               \
<b>proxy_pass &quot;http://127.0.0.1:1024/</b>&quot;;<o:p></o:p></span></p><p \
class=MsoNormal><span lang=TR>       }<o:p></o:p></span></p><p class=MsoNormal><span \
lang=TR><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span lang=TR>       location \
/<b> <span style='color:red'>myrestapiB</span></b>{<o:p></o:p></span></p><p \
class=MsoNormal><span lang=TR>               proxy_set_header X-Forwarded-For \
$remote_addr;<o:p></o:p></span></p><p class=MsoNormal><span lang=TR>               \
proxy_set_header Host $http_host;<o:p></o:p></span></p><p class=MsoNormal><span \
lang=TR>               proxy_pass \
&quot;http://127.0.0.1:1024/&quot;;<o:p></o:p></span></p><p class=MsoNormal><span \
lang=TR>       }<o:p></o:p></span></p><p class=MsoNormal><span \
lang=TR><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span lang=TR>       # deny \
access to .htaccess files, if Apache's document root<o:p></o:p></span></p><p \
class=MsoNormal><span lang=TR>       # concurs with nginx's \
one<o:p></o:p></span></p><p class=MsoNormal><span lang=TR>       location ~ /\.ht \
{<o:p></o:p></span></p><p class=MsoNormal><span lang=TR>               deny   \
all;<o:p></o:p></span></p><p class=MsoNormal><span lang=TR>       \
}<o:p></o:p></span></p><p class=MsoNormal><span \
lang=TR><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span lang=TR>     location = \
/nginx.conf {<o:p></o:p></span></p><p class=MsoNormal><span lang=TR>               \
deny all;<o:p></o:p></span></p><p class=MsoNormal><span lang=TR>       \
}<o:p></o:p></span></p><p class=MsoNormal><span \
lang=TR><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span lang=TR>     # Deny \
access to hidden files (beginning with a period)<o:p></o:p></span></p><p \
class=MsoNormal><span lang=TR>       location ~ /\. {<o:p></o:p></span></p><p \
class=MsoNormal><span lang=TR>                 deny all;<o:p></o:p></span></p><p \
class=MsoNormal><span lang=TR>       }<o:p></o:p></span></p><p class=MsoNormal><span \
lang=TR>}<o:p></o:p></span></p><p class=MsoNormal><span \
lang=TR><o:p>&nbsp;</o:p></span></p><p class=MsoNormal><span \
lang=TR>Thanks<o:p></o:p></span></p><p class=MsoNormal><span lang=TR>Niyazi \
Toros<o:p></o:p></span></p></div></body></html>



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

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic