YoHey
@YoHey
Постоянные проблемы

Как настроить Nginx config на Open server?

Какова проблема. Хочу сделать роутинг на symfony, slim и silex. При переходе на другой роут выдает 404.
Насколько понимаю нужно подправить конфиг. Может кто то рассказать как это сделать?

Исходник nginx 1.8 версии

server {
    listen         %ip%:%httpport%;
    listen         %ip%:%httpsport% ssl;
    server_name    %host% %aliases%;
    
    ssl_certificate               "%sprogdir%/userdata/config/cert_files/server.crt";
    ssl_certificate_key           "%sprogdir%/userdata/config/cert_files/server.key";
    
    #add_header Strict-Transport-Security "max-age=94608000";
    
    # if ($request_method !~* ^(GET|HEAD|POST)$ ){return 403;}
    location ~ /\. {deny all;}

    location / {
        root       "%hostdir%";
        index      index.php index.html index.htm;
    }

    location ~ \.php$ {
        root                               "%hostdir%";
        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";
        }
    }
}
  • Вопрос задан
  • 27865 просмотров
Решения вопроса 1
SimBioT19
@SimBioT19
{{ user.about }}
Конфиги Nginx в OSpanel (OpenServer) настраиваются для каждого домена отдельно.
В папку с доменом поместите файл с конфигами, имеющий название версии Nginx, например, Nginx-1.8_vhost.conf или Nginx-1.10_vhost.

Внутренности моего конфига для root в /public:
server {
    listen         %ip%:%httpport%;
    listen         %ip%:%httpsport% ssl;
    server_name    %host% %aliases%;
    
    ssl_certificate               "%sprogdir%/userdata/config/server.crt";
    ssl_certificate_key           "%sprogdir%/userdata/config/server.key";
    
    #add_header Strict-Transport-Security "max-age=94608000; includeSubDomains; preload";
    
    # if ($request_method !~* ^(GET|HEAD|POST)$ ){return 403;}
    location ~ /\. {deny all;}

    location / {
        root       "%hostdir%/public";
        index      index.php index.html index.htm;
        try_files $uri $uri/ /index.php?_url=$uri&$args;
    }

    location ~ \.php$ {
        root                               "%hostdir%/public";
        try_files $uri $uri/ /index.php?_url=$uri&$args;
        # 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";
        }
    }

}


Не забудьте перезагрузить openserver
Ответ написан
Пригласить эксперта
Ответы на вопрос 2
MobiLux
@MobiLux
https://lysak.github.io
в папке \OSPanel\userdata\config и в файле Nginx-{версия}_vhost.conf.
Нужно добавить или раскомментировать строку в location / :
location / {
try_files $uri $uri/ /index.php?$query_string;
}
Ответ написан
daager
@daager
Если я вас правильно понял, то вам нужно изменить try_files.
try_files $uri /index.php?$args
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы