我正在尝试改进某些开源软件的安装文档,但是我遇到了Web服务器配置的障碍。我已经将此软件与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>
您可以使用在线工具,例如进行快速转换
仍然,您需要寻找丢失的键,这是一个基本的转换:
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;
}
}
我使用此文档页面来获取Nginx的正确基本配置,因为该特定项目使用Symfony:
https://symfony.com/doc/current/setup/web_server_configuration.html#nginx
如此处所述,我需要将fastcgi_pass设置为127.0.0.1:9000以匹配我的PHP-FPM配置。