Nginx

在 nginx 中從頭開始安裝 drupal 6

  • August 19, 2013

所以我試圖在 nginx 上安裝一個新的 drupal 6 站點。我已經成功設置了conf文件和db。當我嘗試訪問mysite.com以便可以按照分步安裝指南進行操作時,它會正確重定向到mysite.com/install.php但返回 403 禁止錯誤。

在我的 conf 文件中,我嘗試將我的 IP 添加到允許的 IP 列表中:

location = /install.php {
   allow 127.0.0.1;
   allow my_ip_address;
   deny all;
}

但是,當我嘗試訪問時mysite.com/install.php,瀏覽器會下載文件而不是執行它。我該怎麼辦?

我可以使用 drush 安裝一個新站點,但我想改用 drupal 的 install.php 文件(向朋友展示它是如何完成的)。

謝謝你。


server {
   server_name www.mysite.com;
   return 301 $scheme://mysite.com$request_uri;

} # server domain return.

server {
   server_name mysite.com;
   root /var/www/mysite.com;

   index index.html index.htm index.php;

   access_log /var/log/nginx/mysite.access.log;
   error_log /var/log/nginx/mysite.error.log;

   location = /favicon.ico {
           log_not_found off;
           access_log off;
   }

   location = /robots.txt {
           allow all;
           log_not_found off;
           access_log off;
   }

   # For drush
   location = /backup {
           deny all;
   }

   # Prevent user from accessing settings.php directly
   location ~ ^/sites/[^/]+/settings.php$ {
           deny all;
   }

   ## Replicate the Apache <FilesMatch> directive of Drupal standard
   ## .htaccess. Disable access to any code files. Return a 404 to curtail
   ## information disclosure. Hide also the text files.
   location ~* ^(?:.+\.(?:htaccess|make|txt|log|engine|inc|info|install|module|profile|po|sh|.*sql|theme|tpl(?:\.php)?|xtmpl)|code-style\.pl|/Entries.*|/Repository|/Root|/Tag|/Template)$ {
           return 404;
   }

   location ~ \..*/.*\.php$ {
           return 403;
   }

   location / {
           # This is cool because no php is touched for static content
           try_files $uri @rewrite;
   }

   location @rewrite {
           # Some modules enforce no slash (/) at the end of the URL
           # Else this rewrite block wouldn't be needed (GlobalRedirect)
           #rewrite ^/(.*)$ /index.php?q=$1&$args;
           rewrite ^ /index.php last;
   }

   # Use an SSH tunnel to access those pages. They shouldn't be visible to
   # external peeping eyes.
   location = /install.php {
           allow 127.0.0.1;
           deny all;
   }

   location = /update.php {
           allow 127.0.0.1;
           deny all;
   }

   location ~ \.php$ {
           fastcgi_split_path_info ^(.+\.php)(/.+)$;
           #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
           include fastcgi_params;
           fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
           fastcgi_intercept_errors on;
           #fastcgi_pass unix:/var/run/php5-cgi/php5.sock;
fastcgi_pass unix:/var/run/php5-fpm.sock;
   }

   ## Drupal 7 generated image handling, i.e., imagecache in core. See:
   ## https://drupal.org/node/371374
   location ~* /sites/.*/files/styles/ {
           access_log off;
           expires 30d;
           try_files $uri @rewrite;
   }

   # Fighting with ImageCache? This little gem is amazing.
   location ~ ^/sites/.*/files/imagecache/ {
           try_files $uri @rewrite;
   }

   location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
           expires max;
           log_not_found off;
   }
}

您的明確location = /install.php覆蓋任何其他location指令。除非在極少數情況下,nginx 僅將請求匹配到單個location.

因此,您的請求匹配到location = /install.php. 但是,這不包含將請求發送到 php-fpm 的任何指令,因此它被作為靜態文件處理並發送到瀏覽器。

有這個根本沒有意義location。無論如何,您都應該在安裝或升級後刪除該install.php文件。所以我會完全刪除那些locations 。

引用自:https://serverfault.com/questions/532042