[HELP] Excute PHP Script per user request then redirect to last position?

36 views
Skip to first unread message

Kholis Respati Agum Gumelar

unread,
Sep 6, 2019, 10:35:23 AM9/6/19
to openresty-en
Hello everyone,

Can you help me to config nginx that have a behavior like this:
when user visit our website, it will excute a php script first,
then when user click a url or go to url, excute the php script first then go to the url that the user desired, I'm stuck
Please help...

the script is in /root/work/script/index.php

here is my server {} config :
server {
    listen [::]:80;
    listen 80;

    server_name example.org;
    access_log logs/access.log;
    error_log logs/error.log info;

    set $script_per_request true;

    location @script {
        root /root/work/script;
        index index.php;
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;
        fastcgi_param  PATH_INFO $fastcgi_path_info;
        include fastcgi_params;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;

        content_by_lua_block {
            ngx.log(ngx.NOTICE, "Script Per Request Executed")
        }

        return ....; <=User Last Visited
    }

    location / {
        if ($script_per_request = true) {
            set $script_per_request false;
            return @script;
        }

        proxy_pass https://localhost:8080/;
include proxy_params;

        set $script_per_request true;
        break;
    }
}

I'm open to all possible configuration...

Thanks before...

Best Regards,

Kholis 

Sergey Gotsulyak

unread,
Sep 30, 2019, 11:11:59 AM9/30/19
to openre...@googlegroups.com

then when user click a url or go to url, excute the php script first then go to the url that the user desired

Try to use JavaScript handler for link clicks. See https://api.jquery.com/on/

__________________________________________________________________________
CONFIDENTIALITY NOTICE: The information contained in the present message (including any information contained in attachments herein) may be confidential and privileged. It may be read, copied and used only by the intended recipient. If you have received it in error please contact the sender (by return e-mail) immediately and delete this message. Any unauthorized use or dissemination of this message in whole or in parts is strictly prohibited. Print this message only if sharp necessary.
УВЕДОМЛЕНИЕ О КОНФИДЕНЦИАЛЬНОСТИ: Информация, содержащаяся в настоящем сообщении (включая любое вложение) может быть конфиденциальной и охраняться действующим законодательством. Сообщение может быть прочитано, скопировано и использовано исключительно лицом, которому сообщение предназначается. Если Вы получили настоящее сообщение по ошибке, пожалуйста, незамедлительно сообщите об этом отправителю (ответным письмом по электронной почте). Любое несанкционированное использование или распространение информации, содержащейся в настоящем сообщении в целом или в части, строго запрещены. Не распечатывайте настоящее сообщение, если в этом нет крайней необходимости.

Zafer Gürel

unread,
Oct 1, 2019, 8:49:29 AM10/1/19
to openre...@googlegroups.com
Hello Everyone,
We (advancity) are using Openresty heavily in our backend. Especially for caching files.
I developed a simple project to simplify cache cleaning operation on nginx. I'm sure there may be better ways but this is our solution for the problem.

We've decided to opensource it and we aim to add other stuff in the future.

You can check it out on github at https://github.com/zafergurel/nginx-cache-cleaner/

Thank you.

Zafer
Reply all
Reply to author
Forward
0 new messages