Configure Nginx with proxy_pass with two locations
Ya I found solution .Its worked for me.
server {
location /test {
proxy_pass http://localhost:3000;
}
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-for $remote_addr;
proxy_connect_timeout 300;
port_in_redirect off;
proxy_pass http://localhost:8080;
}
}
Shankar Kamble
I have developed three app in angular.js and deployed on Heroku . Demo Url:- 1)http://spellcheckgame.herokuapp.com/ 2)http://node-ang-private-demo.herokuapp.com/ 3)https://case-studies-2014.herokuapp.com/ Github Account:- https://github.com/ShankarKamble Representative Angular.js ,Node.js,MongoDB applications which I have developed. 1)https://github.com/ShankarKamble/Riffle-Shuffle-in-Mean-Stack 2)https://github.com/ShankarKamble/Notes-angularJS-directive-NodeJS 3)https://github.com/ShankarKamble/chat-app-with-geolocation 4)https://github.com/ShankarKamble/Angular-Node-one-page-app LinkedIn Profile:- http://in.linkedin.com/pub/shankar-kamble/2b/57a/5a7 I am Shankar Laxman Kamble, Software Engineer with 4 years & 7 Months experience in application & system development. I have comprehensive experience in the entire software project lifecycle, including project planning/scheduling, configuration management, defect management, requirement analysis development. Seeking a challenging role in software development where I can learn, contribute and grow professionally based on my technical and communication skills. Experience in ,Mongodb,Node.js,Angular.js.(Mean Stack) , Javascript , Asp.Net,C#, Jquery,HTML5, CSS, Sql Server. Completed Microsoft Certified Technology Specialist (MCTS). Completed MongoDB course from mongoDB university.
Updated on June 04, 2022Comments
-
Shankar Kamble almost 2 years
I'm trying to configure Nginx to proxy stuff on a localhost
I want localhost to be proxied to localhost:8080, and localhost/test to be proxied to localhost:3000
Here's my current config file
user www-data; worker_processes 4; pid /var/run/nginx.pid; events { worker_connections 768; # multi_accept on; } http { ## # Basic Settings ## sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; # server_tokens off; # server_names_hash_bucket_size 64; # server_name_in_redirect off; include /etc/nginx/mime.types; default_type application/octet-stream; ## # Logging Settings ## access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; ## # Gzip Settings ## access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; ## # Gzip Settings ## gzip on; gzip_disable "msie6"; # gzip_vary on; # gzip_proxied any; # gzip_comp_level 6; ## # nginx-naxsi config ## # Uncomment it if you installed nginx-naxsi ## #include /etc/nginx/naxsi_core.rules; ## # nginx-passenger config ## # Uncomment it if you installed nginx-passenger ## #passenger_root /usr; #passenger_ruby /usr/bin/ruby; ## # Virtual Host Configs ## include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; server { location / { proxy_pass http://localhost:8080; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-for $remote_addr; port_in_redirect off; proxy_connect_timeout 300; } location /test/ { proxy_pass http://localhost:3030; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-for $remote_addr; port_in_redirect off; proxy_connect_timeout 300; } } }
-
Yan Yang over 8 yearsIs it because
/test
should be put before/
, otherwise the situation/test
, which is included in the situation/
, will be redirected according to the first rule?