D
D
Denis2014-10-24 21:52:10
Nginx
Denis, 2014-10-24 21:52:10

Why is the port number added to the resource address on which the nginx virtual host is running?

There is a bunch:
frontend: proxying to several virtual machines from the same IP address nginx
backend: nginx Frontend
configuration - etc/nginx/sites-enable/site_pro.conf

server {
        listen 192.168.1.7:80;
        #access_log /var/log/nginx/proxy.log;
        server_name site.pro;
        server_name_in_redirect on;


        location / {
            proxy_pass http://192.168.1.11:8082;
            proxy_set_header    Host            $host;
            proxy_set_header    X-Real-IP       $remote_addr;
            proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;

set_real_ip_from   0.0.0.0/0;
  }
}

Backend configuration - etc/nginx/sites-enable/site_pro.conf
upstream backend-site_pro {server unix:/var/run/php5-site_pro.sock;}
server {
    listen              8082;
    server_name         localhost;
    root                /var/www/site_pro/www;
    access_log          /var/log/nginx/site_pro-access.log;
    error_log           /var/log/nginx/site_pro-error.log;
    index               index.php;
    rewrite_log         on;
    location /core/ {                                                          $
        deny all;                                                              $
    }
    location / {
        try_files       $uri $uri/ @rewrite;
    }
    location @rewrite {
        rewrite         ^/(.*)$ /index.php?q=$1;

 }
    location ~ \.php$ {
        include         fastcgi_params;
        fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass    backend-site_pro;
    }
    location ~* ^.+\.(jpg|jpeg|gif|css|png|js|ico|bmp)$ {
       access_log       off;
       expires          10d;
       break;
    }
    location ~ /\.ht {

        deny            all;

    }
set_real_ip_from 192.168.1.7;
real_ip_header X-Forwarded-For;
}

Site: site.pro
When adding to the folder with the site, for example, an SMF forum of the form:
site.pro/smf The first access from any browser redirects to:
site.pro:8082/smf If you delete :8082 , and do it again try - everything starts to open as expected.
It is worth the FIRST TIME to go from any other computer - the situation repeats itself.
The rights to the folders are standard, the database is all as usual. If the resources are separated into separate virtual hosts, everything works fine. It is necessary to place "a resource in a resource", how such nonsense begins. Whether it's a forum, WP or phpmyadmin ... the first time it always pops up port: 8082
I broke my head and searched in Google, I can't find anything about it.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yuri Popov, 2014-10-24
@Rentable

These are the features of the engine - it determines the domain name and substitutes it in all links, and the "back" nginx informs the puff of the host with the added port. This is what many do.
The solution is to add the correct http_host (or whatever it is) to fastcgi_param in nginx.

D
Denis, 2014-10-24
@Rentable

Thanks for the answer. Can you be more specific about what to write. In the documentation on nginx.org , we went through fastcgi_param very sparingly - I did not find anything similar.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question