簡體   English   中英

在Nginx配置下執行php腳本

[英]Executing php scripts under a nginx configuration

我在其配置中具有以下Nginx服務器塊

server {
    listen       80;
    server_name mydomain.com;
    location /deploy {
        alias /home/somedir/deploy/;
        }

    # pass the PHP scripts to FastCGI server listening on /var/run/php5-fpm.sock
    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;

    }
  }

我想在網址mydomain.com/deploy/erp/index.php或mydomain.com/deploy/erp上執行php文件

上面的事情下載了php文件而不是執行它。 我在Google上搜索並找到了解決方案,要求您定義www目錄或其他內容。 我只需要在特定目錄中的特定URL上執行文件即可。 我有什么選擇?

您尚未告訴nginx如何處理.php文件。 假設您使用的是php-fpm,則需要這樣的內容:

server {
  listen       80;
  server_name mydomain.com;

  root /home/somedir;

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

  location /deploy {
    try_files $uri $uri/ /index.php?$args;
  }

  location ~ \.php$ {
    try_files $uri =404;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_pass 127.0.0.1:9000;
    include fastcgi_params;
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM