1

I try a simple configuration with an nginx v1.10.13. The configuration :

events
{

}

http 
{
  server 
  {
    listen       80;

    location = /loc1
    {
      proxy_pass http://192.168.0.5:80/;
    }
  }
}

and try this configuration with curl --data "param1=XXX" -X POST http://192.168.0.4:80/loc1

I watch 192.168.0.5 incoming connection and nothing come.

I really don't understand what is wrong, the configuration is very simple. I match all connexion on port 80, and all loc1 location. So why my curl command fail ? curl command return Not found: /...

2 Answers 2

0

Try with other order:

server{
      server_name _;
      root /var/www/;
      index  index.php index.html index.htm;

location / {
    try_files $uri $uri/ /index.php$is_args$args ;
}
This part
location /what_you_want/ {
    proxy_pass      http://192.168.154.102/;
}

    access_log /var/log/nginx/mp_name_access.log;
    error_log  /var/log/nginx/mp_name_error.log;
}

The http{ at the beginning does not make a sense to me

4
  • Thanks for your answer. I try to supress http directive but I obtain ""server" directive is not allowed here". I am not sure to understand, what do is wrong with order ? Because I put location inside server directive, as on your example.
    – geo667
    Commented Apr 16, 2019 at 6:57
  • could you provide me more information? I mean what is the file that you are trying to edit? generally should be a new file in /etc/nginx/sites-enabled/yourfile.conf I always do as the code that I sent you, and I never had a problem, thats why probably need more details :)
    – sysalam0
    Commented Apr 16, 2019 at 14:36
  • I try to write an entire new /etc/nginx/nginx.conf. My goal is to start with a very simple configuration that I will increase step by step. And to supress all configuration I don't understand I start with a new one
    – geo667
    Commented Apr 16, 2019 at 15:43
  • Okay I understand, I recommend you to split the nginx.conf from the virtual hosts, you always can customize the nginx.conf and the vhost separately, Check this link, there is the default nginx conf and the vhost for php, regards! [ github.com/alanmuniz/nginx-example ]
    – sysalam0
    Commented Apr 16, 2019 at 18:01
0

Is this your default configuration? If so, the parameter "server_name" should already be there. What strikes me is the "location" specification. This should be without "=". And with curl you specify the port, which is not necessary for http = 80.

my suggestion would be

http {
  server {
    listen 80;

    location /loc1/ {
      proxy_pass http://192.168.0.5;
    }
  }
}

Since the headers are also important for proxy_pass, I would rather follow the official example. nginx proxy_pass example

1
  • Thanks, I try to add "server_name _;" and "proxy_set_header Host $host;" and "proxy_set_header X-Real-IP $remote_addr;". I supress port inside curl command, but I alway obtain error. On nginx access log, there is "192.168.0.10 - - [16/Apr/2019:12:30:52 +0200] "POST /loc1 HTTP/1.1" 404 12 "-" "curl/7.58.0""
    – geo667
    Commented Apr 16, 2019 at 11:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .