【问题标题】:Nginx config for vue app + php symfony backend用于 vue 应用程序 + php symfony 后端的 Nginx 配置
【发布时间】:2019-10-25 07:48:34
【问题描述】:

我想在 example.com/api 等子目录中运行 symfony 应用程序。我的配置有什么问题?我收到 404 没有其他错误

server {
       listen 80;
       listen [::]:80;

       server_name www.example.com example.com; 

        location /api {
                alias /var/www/dev/symfony-server/public/;
                try_files $uri index.php$is_args$args;
                fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
                fastcgi_split_path_info ^(.+\.php)(/.*)$;
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
                fastcgi_param DOCUMENT_ROOT $realpath_root;
                internal;
        }
}

【问题讨论】:

  • 你的问题是什么?你有错误吗?你能告诉我们任何错误吗?你期待看到什么?你在看什么?你的问题根本不完整。
  • @killstreet 抱歉,我更新了我的帖子。我只收到 404 没有错误日志
  • 你还没有为 nginx 设置根目录来查找你的文件
  • 我指定了别名。

标签: php nginx server backend devops


【解决方案1】:

你缺少你的根目录供你的 nginx 查看。

尝试以下方法:

server {
    listen 127.0.0.1:80;
    server_name dev.blog.local blog.local www.blog.local;
    root /Volumes/git/blog/public;
    location / {
        # try to serve file directly, fallback to index.php
        try_files $uri /index.php$is_args$args;
    }

    location ~ ^/(index)\.php(/|$) {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
    }
    location ~ \.php$ {
        return 404;
    }
}

【讨论】:

  • 你在哪里指定'/api/路径?
  • 这是一个例子,不是完整的答案。您可以根据自己的要求对其进行修改。
  • 你真的以为我没试过吗? :D 但我解决了一个问题。问题是如果您在某个目录下有别名和php应用程序,$fastcgi_script_name路径无效,您必须手动设置它
猜你喜欢
  • 2019-05-10
  • 2020-03-07
  • 2019-09-17
  • 2020-04-06
  • 2021-05-10
  • 1970-01-01
  • 2015-03-13
  • 1970-01-01
  • 2021-01-30
相关资源
最近更新 更多