H
H
hagen17782015-08-28 10:01:38
Nginx
hagen1778, 2015-08-28 10:01:38

How to properly configure nginx for two hosts?

I'm trying to "start" https://github.com/hscstudio/angular1-yii2/blob/ma...
At the end of the readme it says:
Set up two hosts in your webserver. One should point to web-client, aother to web-service/web
That's the problem... I'm running everything on openserver, nginx 1.6. I put Nginx-1.6_vhost.conf in the project folder and wrote in it:

server {
    listen         %ip%:%httpport%;
    listen         %ip%:%httpsport% ssl;
    server_name    %host% %aliases%;
    # if ($request_method !~* ^(GET|HEAD|POST)$ ){return 403;}
    location ~ /\. {deny all;}


    location / {
                            root "%hostdir%/web-client";
                       }

    location /web {
        alias  %hostdir%/web-service/web;

        rewrite  ^(/web)/$ $1 permanent;
        try_files  $uri /web-service/web/index.php?$args;
    }

    location ~ \.php$ {
        root                               "%hostdir%/web-service/web";
        try_files                          $uri =404;
        # if (!-e $document_root$document_uri){return 404;}
        fastcgi_pass                       backend;
        fastcgi_index                      index.php;
        fastcgi_buffers                    4 64k;
        fastcgi_connect_timeout            1s;
        fastcgi_ignore_client_abort        off;
        fastcgi_next_upstream              timeout;
        fastcgi_read_timeout               5m;
        fastcgi_send_timeout               5m;
        fastcgi_param    CONTENT_TYPE      $content_type;
        fastcgi_param    CONTENT_LENGTH    $content_length;
        fastcgi_param    DOCUMENT_URI      $document_uri;
        fastcgi_param    DOCUMENT_ROOT     $document_root;
        fastcgi_param    GATEWAY_INTERFACE CGI/1.1;
        fastcgi_param    HTTPS             $https;
        fastcgi_param    QUERY_STRING      $query_string;
        fastcgi_param    REQUEST_METHOD    $request_method;
        fastcgi_param    REQUEST_URI       $request_uri;
        fastcgi_param    REMOTE_ADDR       $remote_addr;
        fastcgi_param    REMOTE_PORT       $remote_port;
        fastcgi_param    SERVER_ADDR       $server_addr;
        fastcgi_param    SERVER_PORT       $server_port;
        fastcgi_param    SERVER_NAME       $host;
        fastcgi_param    SERVER_PROTOCOL   $server_protocol;
        fastcgi_param    SERVER_SOFTWARE   nginx;
        fastcgi_param    SCRIPT_FILENAME   $document_root$fastcgi_script_name;
        fastcgi_param    SCRIPT_NAME       $fastcgi_script_name;
        fastcgi_param    TMP               "%sprogdir%/userdata/temp";
        fastcgi_param    TMPDIR            "%sprogdir%/userdata/temp";
        fastcgi_param    TEMP              "%sprogdir%/userdata/temp";
    }


    location /openserver/ {
        root     "%sprogdir%/modules/system/html";
        index    index.php;
        %allow%allow    all;
        allow    127.0.0.0/8;
        allow    ::1/128;
        allow    %ips%;
        deny     all;
        location /openserver/server-status {
            stub_status on;
        }
        location ~ ^/openserver/.*\.php$ {
            root                               "%sprogdir%/modules/system/html";
            fastcgi_pass                       backend;
            fastcgi_index                      index.php;
            fastcgi_buffers                    4 64k;
            fastcgi_connect_timeout            1s;
            fastcgi_ignore_client_abort        off;
            fastcgi_next_upstream              timeout;
            fastcgi_read_timeout               5m;
            fastcgi_send_timeout               5m;
            fastcgi_param    CONTENT_TYPE      $content_type;
            fastcgi_param    CONTENT_LENGTH    $content_length;
            fastcgi_param    DOCUMENT_URI      $document_uri;
            fastcgi_param    DOCUMENT_ROOT     $document_root;
            fastcgi_param    GATEWAY_INTERFACE CGI/1.1;
            fastcgi_param    HTTPS             $https;
            fastcgi_param    QUERY_STRING      $query_string;
            fastcgi_param    REQUEST_METHOD    $request_method;
            fastcgi_param    REQUEST_URI       $request_uri;
            fastcgi_param    REMOTE_ADDR       $remote_addr;
            fastcgi_param    REMOTE_PORT       $remote_port;
            fastcgi_param    SERVER_ADDR       $server_addr;
            fastcgi_param    SERVER_PORT       $server_port;
            fastcgi_param    SERVER_NAME       $host;
            fastcgi_param    SERVER_PROTOCOL   $server_protocol;
            fastcgi_param    SERVER_SOFTWARE   nginx;
            fastcgi_param    SCRIPT_FILENAME   $document_root$fastcgi_script_name;
            fastcgi_param    SCRIPT_NAME       $fastcgi_script_name;
            fastcgi_param    TMP               "%sprogdir%/userdata/temp";
            fastcgi_param    TMPDIR            "%sprogdir%/userdata/temp";
            fastcgi_param    TEMP              "%sprogdir%/userdata/temp";
        }
    }

}

I just can't get through to yii - I get not found all the time.
How to properly configure nginx here?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sindrom, 2015-08-28
@hagen1778

If you are using openserver and you need to set up two hosts, then there is no need to manually edit the nginx configs at all, especially in this way.
As far as I understand from the description in the readme, you need to create one host for the client application (frontend), and another host for the api (backend). In this case, both hosts must point to the same directory, but the second must point to the web subdirectory.
It's very simple.
In the openserver settings, open the "Domains" tab and configure two hosts manually:
vRfyT

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question