Forbidden location when using alias in nginx for relative urls

前端 未结 2 1544
再見小時候
再見小時候 2021-01-02 08:32

I am trying to set up roundcube / phpldapadmin / ... with nginx on relative urls, e.g.:

example.com/roundcube
example.com/phpldapadmin

Firs

相关标签:
2条回答
  • 2021-01-02 08:46

    The location and alias should both have a trailing / or neither have a trailing /. But in your case, you should be using root instead of alias for both location blocks.

    location /roundcube {
        root /var/www;
        index index.php;
    
        location ~ \.php$ {
            try_files $uri =404;
    
            fastcgi_pass unix:/var/run/php5-fpm.sock;
    
            include /etc/nginx/fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }
    }
    
    location /phpmyadmin {
        root  /usr/share;
        index  index.php index.html index.htm;
    
        location ~ \.php$ {
            try_files $uri =404;
    
            fastcgi_pass unix:/var/run/php5-fpm.sock;
    
            include /etc/nginx/fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }
    }
    

    The fastcgi_index will not do anything in a location that only matches .php (see this document).

    The SCRIPT_FILENAME parameter is needed in both blocks (or neither if it is already in /etc/nginx/fastcgi_params).

    0 讨论(0)
  • 2021-01-02 08:54

    Alternatively you can try to write at the top of nginx.conf >> user username

    Since I am using AWS Linux EC2 instance I wrote

    user ec2-user;
    

    instead of

    user nginx;
    

    This solves the problem by giving all the required permissions

    0 讨论(0)
提交回复
热议问题