Overhang.io

Nginx web proxy can't work

I installed tutor on aliyun cloud host, because I don’t have a domain name, I think I need a reverse proxy to proxypass the requests to lms and cms. But I don’t know what’s wrong, the nginx is always serving default nginx welcome page to me when I request with my IP address. Even if I changed my port from 80 to 8080. Everything works fine when I use curl on the host with terminal. But when I access http://IPADDRESS:8080 from my local computer browser, it just shows default nginx welcome page.

My nginx conf file is

Blockquote
server {
listen 8080;
server_name www.myopenedx.com preview.www.myopenedx.com studio.www.myopenedx.com;
server_tokens off;
location /lms/ {
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://localhost:81;
}
}

and when I changed the location from ‘/lms/’ to root location, it showed a bad request with error code 400.

What is the problem, and how can I access both lms and cms without a domain name?
Nginx configuration is like magic to me, even if I read and searched a lot of documentation and tutorials.
Thanks in advance.

Hi @teruun! There are two ways I can answer your question: I can give you the short or the long answer :smile:
The short answer is that you should get rid of the web proxy and during configuration set your server ip as the lms host. Then access your lms at http://<server ip>. The studio will not be available.
For the long answer you will have to wait until I get to my computer :slight_smile:

Thank you @regis . http://<server ip> works before I type the proxy command, in order to make the studio work, I typed the proxy command in tutor documentation, and then tried something I don’t remember, now totally lost:rofl:. I’ll wait for you long answer.

Ok, let’s go for the long explanation.

I installed tutor on aliyun cloud host, because I don’t have a domain name, I think I need a reverse proxy to proxypass the requests to lms and cms.

No you don’t! A reverse proxy does not have anything to do with the fact that you do not own a domain name. A reverse proxy is only required when you need to setup multiple web services on the same server, as explained in the docs.

But I don’t know what’s wrong, the nginx is always serving default nginx welcome page to me when I request with my IP address. Even if I changed my port from 80 to 8080. Everything works fine when I use curl on the host with terminal. But when I access http://IPADDRESS:8080 from my local computer browser, it just shows default nginx welcome page.

This is because of the following directive in the web proxy:

server_name www.myopenedx.com preview.www.myopenedx.com studio.www.myopenedx.com;

This means that only web requests for these server names will be redirected to the LMS/CMS. Other requests will be served by the default nginx server, which will simply print the nginx welcome message.

and when I changed the location from ‘/lms/’ to root location, it showed a bad request with error code 400.

There are two things to understand here. First, despite the server_name directive, the nginx conf file is the default server for all requests incoming on port 8080. So, when you setup location /, all requests are forwarded to the LMS. But, and this is the second thing to understand, the LMS django application is configured to accept only requests that were sent to the right host: either www.myopenedx.com or localhost: https://github.com/overhangio/tutor/blob/master/tutor/templates/apps/openedx/settings/lms/production.py#L8
When the LMS receives a request that does not match one of these hosts, it responds with a 400 error.

I suggest you get rid of the web proxy: uninstall nginx and reset tutor setting:

tutor config save --set WEB_PROXY=false

Then, run tutor local quickstart again. During configuration, set your server IP address as the LMS host. DO NOT enable https. You should be able to access your platform on port 80: http://<your server ip>

As an alternative, if your personal computer is running on Linux, you can configure myopenedx.com and studio.myopenedx.com as your LMS/CMS hosts. Then configure your computer to point these domain names to your server: to do so, add the following content to the /etc/hosts file on your personal computer:

<your server IP> myopenedx.com studio.myopenedx.com

Thanks, regis. I think I should buy a domain name so that can make studio work.

1 Like