Nginx location directive doesn't seem to be working. Am I missing something?

后端 未结 4 774
逝去的感伤
逝去的感伤 2020-12-07 09:59

I\'ve set up Nginx as my main web server and have two Mochiweb based servers behind it. Certain requests are reverse-proxied to these two servers. now, I want to access php

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-07 10:46

    I struggled with this for hours now and none of the solutions discussed above worked to my case (since i needed to run index.php, index.php with arguments, and other php scripts than index.php), but finally reached the working configurations as the following:

        location /php-app {
        passenger_enabled off;
        alias /path/to/php-app/$1;
        index index.php index.html;
        try_files $uri $uri/ @rewrite;
       }
    
       location @rewrite {
        rewrite ^/php-app(.*)$ /index.php?q=$1 last;
       }
    
    location ~ \.php$ {
        alias /path/to/php-app/$1;
        rewrite ^/php-app(.*)$ $1 last;
        passenger_enabled off;
        fastcgi_pass unix:/tmp/php-fpm.socket;
        fastcgi_index index.php;
        include /etc/nginx/fastcgi_params;
        fastcgi_param SCRIPT_FILENAME /path/to/php-app$fastcgi_script_name;
        fastcgi_intercept_errors on;
        }
    

提交回复
热议问题