首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >nginx位置不能解释php

nginx位置不能解释php
EN

Stack Overflow用户
提问于 2017-12-08 23:50:11
回答 0查看 185关注 0票数 1

我要疯了才能理解这个nginx vhost配置。我的问题是php的位置,当它在/v2之外正常工作时,它不会将/v2内容发送到php-fpm。谁能给我指出错误所在?

代码语言:javascript
复制
server {
  listen 443 ssl;
  include ssl.conf;
   include hardening.conf;
   server_name myapp.domain.com myapp;
   ssl_certificate /etc/pki/tls/certs/myapp.domain.com.crt;
   ssl_certificate_key /etc/pki/tls/private/myapp.domain.com.key;
   access_log /var/log/nginx/myapp.domain.com-access.log main;
   error_log /var/log/nginx/myapp.domain.com-error.log notice;
   root /var/www/html/myapp.domain.com;

   location ~ /\.ht {
     deny  all;
   }

   location ~ /v2 {
     alias /var/www/html/myapp.domain.com/version-2/web;
     try_files $uri index.php$is_args$args;
   }

   location ~ [^/]\.php(/|$) {
     fastcgi_split_path_info ^(.+?\.php)(/.*)$;
     if (!-f $document_root$fastcgi_script_name) {
       return 404;
     }

     # Mitigate https://httpoxy.org/ vulnerabilities
     fastcgi_param HTTP_PROXY "";

     fastcgi_pass localhost:9000;
     fastcgi_index index.php;
     include fastcgi_params.conf;
   }
 }

根据评论,我正在尝试嵌套位置解决方案,但当文件系统上存在/var/www/html/myapp.domain.com/version-2/web/index.php时,当我尝试https://myapp.domain.com/v2/index.php时,我收到了404。同样,正如在给出的链接中所解释的,我将我的位置从^修改为^~。知道出什么问题了吗?

代码语言:javascript
复制
server {
  listen 443 ssl;
  include ssl.conf;
   include hardening.conf;
   server_name myapp.domain.com myapp;
   ssl_certificate /etc/pki/tls/certs/myapp.domain.com.crt;
   ssl_certificate_key /etc/pki/tls/private/myapp.domain.com.key;
   access_log /var/log/nginx/myapp.domain.com-access.log main;
   error_log /var/log/nginx/myapp.domain.com-error.log notice;
   root /var/www/html/myapp.domain.com;

   location ~ /\.ht {
     deny  all;
   }

   location ^~ /v2 {
     alias /var/www/html/myapp.domain.com/version-2/web;
     try_files $uri index.php$is_args$args;

     location ~ [^/]\.php(/|$) {
       fastcgi_split_path_info ^(.+?\.php)(/.*)$;
       if (!-f $document_root$fastcgi_script_name) {
         return 404;
       }

       # Mitigate https://httpoxy.org/ vulnerabilities
       fastcgi_param HTTP_PROXY "";

       fastcgi_pass localhost:9000;
       fastcgi_index index.php;
       include fastcgi_params.conf;
     }

   }

   location ~ [^/]\.php(/|$) {
     fastcgi_split_path_info ^(.+?\.php)(/.*)$;
     if (!-f $document_root$fastcgi_script_name) {
       return 404;
     }

     # Mitigate https://httpoxy.org/ vulnerabilities
     fastcgi_param HTTP_PROXY "";

     fastcgi_pass localhost:9000;
     fastcgi_index index.php;
     include fastcgi_params.conf;
   }
 }
EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47717756

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档