How to build a proxy server from Ubuntu to nginx

Asked 1 years ago, Updated 1 years ago, 99 views

Related questions (https://hashcode.co.kr/questions/1795/aws-%EC%9D%98-ec2-%EB%A1%9C-%EC%9A%B0%EB%B6%84%ED%88%AC-%EC%84%9C%EB%B2%84-%EA%B5%AC%EC%B6%95%ED%95%98%EC%98%80%EC%8A%B5%EB%8B%88%EB%8B%A4-%ED%8F%AC%ED%8A%B8-%ED%8F%AC%EC%9B%8C%EB%94%A9%EC%97%90-%EB%8C%80%ED%95%B4%EC%84%9C)

We built a web server (Port: 9000) with node.js in Ubuntu with EC2 of AWS.

Elastic IP is domain connected to route 53 solution. http://XXX.XXX.XXX.XXX -> Access the node.js web application.

And to build a proxy server,

After installing nginx on Ubuntu

server {

    listen 80;
    server_name example.com www.example.com;

    location / {
      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;
      proxy_set_header X-NginX-Proxy true;

      proxy_pass http://127.0.0.1:9000/;
      proxy_redirect off;
    }

    log_not_found off;

    gzip on;
    gzip_comp_level 2;
    gzip_proxied any;
    gzip_min_length  1000;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript text/x-js;
 }

Created nginx.conf file.

If you restart nginx and node.js and try to connect to example.com, the index page in nginx is output. So when I went to example.com:9000, I saw the node.js web application page.

I don't think the nginx.conf setting is a problem or it doesn't work.

ubuntu proxy nginx node.js

2022-09-22 21:57

1 Answers

Try removing the server_name entry from the settings below.

The server {} block applies only to requests that have entered the domain with that setting. Try removing / after port 9000.

  listen 80;
  # # server_name example.com www.example.com;
  proxy_pass http://127.0.0.1:9000;


2022-09-22 21:57

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.