将 Apache 配置转换为 Nginx
Convert Apache configuration to Nginx
我正在尝试改进一些开源软件的安装文档,但我在 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 配置。
我正在尝试改进一些开源软件的安装文档,但我在 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 配置。