繁体   English   中英

Wordpress 的 Nginx 配置沿 Symfony 运行

[英]Nginx configuration for Wordpress running along side Symfony

我有两个应用程序:

  • 位于/var/www/html/wordpress的 wordpress 站点
  • symfony 应用程序位于/var/www/html/symfony

wordpress 应用程序作为主域( domain.com )运行。

我想实现以下行为:

  • 用户访问 URL domain.com/example1
  • nginx 重定向到 Symfony 路由/example1

使用我当前的配置 nginx 已经重定向到 Symfony 应用程序。

它正确加载了 wordpress 站点及其管理仪表板。

问题:

nginx 返回 Symfony 主页 ( / ) 而不是/example1

URLs domain.com/example1domain.com/example2加载 Symfony 主页,而不是在 Symfony 应用程序中创建的相应路由。

我的 nginx 配置:

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name domain.com;
    server_tokens off;
    root /var/www/html/wordpress;
    index index.php index.html index.htm;

    index index.html index.htm index.php;
     client_max_body_size 500M;
#    charset utf-8;

    location / {
        # CUSTOM
        satisfy any;

charset utf-8;
        allow 1.1.1.0/32;
        deny  all;

        try_files $uri $uri/ /index.php?$query_string;
    }

### start test

location ^~ /example1 {

      satisfy any;
      allow 1.1.1.0/32;
         deny  all;

      index index.php;
      alias /var/www/html/symfony/current/public/;
      try_files $uri $uri/ /index.php?$query_string;
      location ~ \.php$ {
                    try_files $uri =404;
                    fastcgi_split_path_info ^(.+\.php)(/.+)$;
                    #fastcgi_pass 127.0.0.1:9000;
                    fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
                    fastcgi_index index.php;
                    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                    include fastcgi_params;
      }
 }




location ^~ /example2 {
      satisfy any;
      allow 1.1.1.0/32;
         deny  all;

      index index.php;
      alias /var/www/html/symfony/current/public/;
      try_files $uri $uri/ /index.php;
      location ~ \.php$ {
                    try_files $uri =404;
                    fastcgi_split_path_info ^(.+\.php)(/.+)$;
                    #fastcgi_pass 127.0.0.1:9000;
                    fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
                    fastcgi_index index.php;
                    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                    include fastcgi_params;
      }
 }


 location ~ ^((?!\/example1).)*$ { #this regex is to match anything but `/example1`
      satisfy any;
      allow 1.1.1.0/32;
         deny  all;

         index index.php;
         root /var/www/html/wordpress;
         try_files $uri $uri/ /index.php?$request_uri;
         #try_files $uri $uri/ /index.php?do=$request_uri;
         location ~ \.php$ {
                 try_files $uri =404;
                 fastcgi_split_path_info ^(.+\.php)(/.+)$;
                 #fastcgi_pass 127.0.0.1:9000;
                 fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
                 fastcgi_index index.php;
                 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                 include fastcgi_params;

       }


}



### end test

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

    access_log off;
    error_log  /var/log/nginx/domain.com-error.log error;

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;

        # CUSTOM
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
        internal;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }

您可能会在设置 fastcgi_params 后使用文件fastcgi_params中的默认值覆盖fastcgi_*参数。

代替:

fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

# the following line loads defaults from file `fastcgi_params`
include fastcgi_params;

include指令移到顶部,如下所示:

include fastcgi_params;

# the following fastcgi_* parameters override the defaults in file `fastcgi_params`
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM