1

Hello guys I want to make an nginx config for my server. I want to serve localhost for testing for now. So I set up inside a myWebsite.conf file which I include into the nginx.conf file via include /path/to/myWebsite.conf

I want to make my server block that way that it can serve the static index.html, css files and js files when the url is localhost:8080 and when the url is localhost:8080/services I want nginx to reverse proxy a gunicord server that is up and running and is serving my falcon app (back end python framework)

The way I built my server block is following

server { listen 8080; server_name localhost; index index.html location ~ / { root /path/to/var/www/mySite (where I have only my index.html page) } location ~ /services { proxy_pass http://127.0.0.1:8000; (gunicorn server running) } add_header Cache-Control no-cache; (no cache for testing reasons) } 

The result I am getting is that the server is only serving the index.html and nothing else. When I type localhost:8080/services I dont have access to my api methods on my python program. Can you help me please on which part should I change to make it play? Or I have something completely wrong in the way I am trying to do this?

1 Answer 1

1

Add some trailing slashes in where due, and probably get rid of the tilde ~ as these are to do with regluar expression matches.

Try like this:

server { listen 8080; server_name localhost; index index.html location / { root /path/to/var/www/mySite; # (where I have only my index.html page) } location /services/ { proxy_pass http://127.0.0.1:8000/; #(gunicorn server running) proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } add_header Cache-Control no-cache; #(no cache for testing reasons) } 
3
  • Thank you for the answer. Now it works as intended! Commented Jan 26, 2019 at 14:35
  • No problem. On Stackexchange you should accept the accepted answer with the tick ;-) Commented Jan 26, 2019 at 14:38
  • Aha yeah forgot that. Kinda new on this. Thx again Commented Jan 26, 2019 at 14:45

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.