【问题标题】:Convert Apache configuration to Nginx [closed]将 Apache 配置转换为 Nginx [关闭]
【发布时间】:2019-11-22 01:43:20
【问题描述】:

我正在尝试改进一些开源软件的安装文档,但我遇到了网络服务器配置的障碍。我有这个软件可以很好地与 Apache 配合使用,但我需要在文档中使用 Nginx 以保持一致性。使用这种 Apache 配置如何在 Nginx 中获得相同的结果?

<VirtualHost *:80>
        ServerName example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/publisher/public

        <Directory /var/www/publisher/public>
                AllowOverride None
                Order Allow,Deny
                Allow from All
                Header set Access-Control-Allow-Origin http://example2.com

                <IfModule mod_rewrite.c>
                    Options -MultiViews
                    RewriteEngine On
                    RewriteCond %{REQUEST_FILENAME} !-f
                    RewriteRule ^(.*)$ index.php [QSA,L]
                </IfModule>
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

【问题讨论】:

    标签: apache nginx nginx-location


    【解决方案1】:

    您可以使用在线工具,例如快速转换

    仍然需要寻找丢失的键,这是一个基本的转换:

    server_name example.com;
    root /var/www/publisher/public;
    error_log ${APACHE_LOG_DIR}/error.log;
    
    location / {
      if (!-e $request_filename){
        rewrite ^(.*)$ /index.php break;
      }
    }
    

    【讨论】:

    • 在发布此问题之前,我尝试使用您链接的第一个在线工具。我的配置与您的答案中的配置相同,它修复了我得到的内部服务器错误,但现在我得到一个 403 禁止错误。我检查了文件夹权限并确保它是公开的。知道那可能是什么吗?还是和配置完全无关?
    • 403 可能是各种事情的结果,只需快速回顾一下这篇文章,希望它对您有所帮助ionos.com/community/server-cloud-infrastructure/nginx/…
    【解决方案2】:

    我使用此文档页面来获取 Nginx 的正确基本配置,因为这个特定项目使用 Symfony:

    https://symfony.com/doc/current/setup/web_server_configuration.html#nginx

    如上所述,我需要将 fastcgi_pass 设置为 127.0.0.1:9000 以匹配我的 PHP-FPM 配置。

    【讨论】:

      猜你喜欢
      • 2021-12-28
      • 2021-04-04
      • 2014-09-24
      • 2011-08-15
      • 2012-08-25
      • 1970-01-01
      • 2020-01-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多