nginx download php files in symlinks in plaats van uitvoeren

Pagina: 1
Acties:

  • Mexxus
  • Registratie: Januari 2004
  • Laatst online: 20-09 17:01
Hi all,

Ik heb een Ubuntu server met nginx en php-fpm opgezet met daarin 1 virtual host (default). PHP files worden in de root folder (/home/buddy/www) gewoon geexecuteerd, maar zodra de files in een symlink staan (/phpmyadmin) dan niet meer. Zodra een files in een symlink staan dan worden ze gedownload als platte text-files. Ik download dan gewoon een php-code file.

Ik zie door de bomen het bos niet meer en heb enorm veel google-tips al geprobeerd, zonder resultaat. Kunnen jullie mij helpen?

Hier de belangrijkste configs. Mochten jullie iets missen, let me know:

sites-available/default:

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
server {
        listen   80; ## listen for ipv4; this line is default and implied
        listen   [::]:80 default ipv6only=on; ## listen for ipv6

        root /home/buddy/www/;
        index index.php index.html index.htm;

        disable_symlinks off;
        autoindex on;



        # Make site accessible from http://localhost/
        server_name 37.252.***.***;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to index.html
                try_files $uri $uri/ /index.html;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules
        }

        # redirect server error pages to the static page /50x.html
        #
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root /usr/share/nginx/www;
        }

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
                try_files $uri =404;
                include fastcgi_params;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        location ~ /\.ht {
                deny all;
        }
}


/etc/nginx/nginx.conf:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
user www-data;
worker_processes 1;

error_log /var/log/nginx/error.log;

pid /var/run/nginx.pid;

events {
        worker_connections 1024;
}

http {
        # increase alowed domainnames lenght
        server_names_hash_bucket_size 64;

        # increase proxy buffer size to avoid problems with HTMLParser
        proxy_buffers 8 256k;
        proxy_buffer_size 256k;

        sendfile on;
        tcp_nopush on;
        keepalive_timeout 5;
        tcp_nodelay on;
        types_hash_max_size 2048;

        include /etc/nginx/mime.types;
        #default_type application/octet-stream;
        default_type text/html;
        error_log /var/log/nginx/error.log;

        #gzip options
        gzip  on;
        gzip_http_version 1.1;
        gzip_vary on;
        gzip_comp_level 6;
        gzip_proxied any;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript text/x-js;
        gzip_buffers 16 8k;
        gzip_disable "MSIE [1-6]\.(?!.*SV1)";

        server {

                # Pass PHP scripts to PHP-FPM
                location ~* \.php$ {

                        fastcgi_index   index.php;
                        fastcgi_pass    127.0.0.1:9000;

                        #fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;
                        include         fastcgi_params;
                        fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
                        fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
                }

        }

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;

}


ls -la /home/buddy/www
code:
1
2
3
4
5
total 12
drwxrwxr-x 2 buddy buddy 4096 Sep 21 13:33 .
drwxr-xr-x 4 buddy buddy 4096 Sep 21 13:54 ..
-rw-r--r-- 1 buddy buddy   20 Sep 21 13:23 index.php
lrwxrwxrwx 1 buddy buddy   21 Sep 21 13:33 phpmyadmin -> /usr/share/phpmyadmin


ls -la /home/buddy/www/phpmyadmin/
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
total 1148
drwxr-xr-x  8 root root   4096 Sep 21 13:27 .
drwxr-xr-x 83 root root   4096 Sep 21 13:27 ..
-rw-r--r--  1 root root  11230 Feb 18  2012 browse_foreigners.php
-rw-r--r--  1 root root   1621 Feb 18  2012 bs_disp_as_mime_type.php
-rw-r--r--  1 root root   2060 Feb 18  2012 bs_play_media.php
-rw-r--r--  1 root root   4000 Feb 18  2012 changelog.php
-rw-r--r--  1 root root    363 Feb 18  2012 chk_rel.php
-rw-r--r--  1 root root   3746 Feb 18  2012 config.sample.inc.php
-rw-r--r--  1 root root   4060 Feb 18  2012 db_create.php
-rw-r--r--  1 root root  10137 Feb 18  2012 db_datadict.php
-rw-r--r--  1 root root   2876 Feb 18  2012 db_export.php
-rw-r--r--  1 root root    466 Feb 18  2012 db_import.php
[knip] ..... [/knip]
-rw-r--r--  1 root root   4879 Feb 18  2012 user_password.php
-rw-r--r--  1 root root   5354 Feb 18  2012 view_create.php
-rw-r--r--  1 root root   2802 Feb 18  2012 view_operations.php
-rw-r--r--  1 root root   1121 Feb 18  2012 webapp.php

  • cannibal
  • Registratie: Maart 2001
  • Laatst online: 02-10 15:39
In het ene geval gebruik je php-fpm voor fast cgi, in het andere de port 9000 op localhost. Even controleren hoe php-fpm geconfigureerd staat.

Verder even ook logfile bekijken, mogelijk geeft dat aan waar er iets fout gaat.

  • Mexxus
  • Registratie: Januari 2004
  • Laatst online: 20-09 17:01
Ik heb de FastCGI block weg gehaald en nu enkel de php-fpm er in geconfigureerd. Het feit dat de php-scripts in de root foler gewoon werken, lijkt me dat PHP goed geconfigureerd staat. als ik daar een phpinfo(); doe dan werkt dat gewoon.

Hoe kan ik dat verder controleren?

  • cannibal
  • Registratie: Maart 2001
  • Laatst online: 02-10 15:39
Ik ben verder geen expert, maar kan mijn file voor server config hier neerzetten.
Dus mogelijk verre van perfect, maar heb nginx pas van de week voor het eerst geinstalleerd.

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
server {
  listen                80;
  server_name           <www.example.nl>;

  root                  /usr/local/www/subpath;
  index                 index.php;

  location / {
    try_files $uri $uri/ =404;
  }

location ~ \.php$ {
    try_files $uri $uri/ =404;
    include        fastcgi_params;
    fastcgi_pass   unix:/var/run/php-fpm.sock;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_NAME  $fastcgi_script_name;
    fastcgi_param  SCRIPT_FILENAME  $request_filename;
}

}

Acties:
  • 0 Henk 'm!

  • Creepy
  • Registratie: Juni 2001
  • Laatst online: 22:11

Creepy

Tactical Espionage Splatterer

Zaken over webserver configuratie e.d. passen beter in Non-Windows Operating Systems dan in Programming. move -> Non-Windows Operating Systems.

"I had a problem, I solved it with regular expressions. Now I have two problems". That's shows a lack of appreciation for regular expressions: "I know have _star_ problems" --Kevlin Henney


Acties:
  • 0 Henk 'm!

  • Hero of Time
  • Registratie: Oktober 2004
  • Laatst online: 22:26

Hero of Time

Moderator LNX

There is only one Legend

Ipv een symlink te maken in je document root, kan je beter een alias maken in je config. Iets als dit:
code:
1
2
3
location /phpmyadmin {
documentroot /usr/share/phpmyadmin
}


Als 't niet helemaal werkt, moet je even Google raadplegen voor de Apache configuratie. Ik gebruik in mijn voorbeeld Location, maar een alias oid is ook mogelijk, maar ik weet dat niet uit m'n hoofd. En er moet natuurlijk nog wel wat over blijven voor je om te leren ;).

Commandline FTW | Tweakt met mate

Pagina: 1