如何将此Apache VHost迁移到Nginx

时间:2019-02-04 11:12:14

标签: nginx hosting microservices

我相对较新,想在Nginx上测试服务,但是我正在努力将此Apache配置转换为Nginx。

<VirtualHost *:80>

  ServerName api.my-site.de

  DocumentRoot /var/www/api.my-site.de/current/public

  <Directory "/var/www/api.my-site.de/current/public">
      AllowOverride FileInfo AuthConfig Limit Options=All,MultiViews Indexes
      Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
      Order deny,allow
      Require all granted
  </Directory>

</VirtualHost>


<VirtualHost *:443>

  ServerName api.my-site.de

  DocumentRoot /var/www/api.my-site.de/current/public

  <Directory "/var/www/api.my-site.de/current/public">
      AllowOverride FileInfo AuthConfig Limit Options=All,MultiViews Indexes
      Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
      Order deny,allow
  </Directory>

 SSLEngine on

 SSLCertificateFile           /etc/ssl/private/wildcard.my-site.de.crt
 SSLCertificateKeyFile     /etc/ssl/private/wildcard.my-site.de.key
 SSLCertificateChainFile  /etc/ssl/private/chain.crt

</VirtualHost>

有人可以在这里帮忙吗?由于nginx没有.htaccess一样,我不确定该如何处理所有标签。

当前草稿

server {
    listen 80;
    listen [::]:80 ipv6only=on;
    listen 443 ssl;
    listen [::]:443 ipv6only=on ssl;

    server_name api.my-site.de

    location / {
        root   /var/www/api.my-site.de/current/public;
    }

    ssl_certificate      /etc/ssl/private/wildcard.my-site.de.crt;
    ssl_certificate_key  /etc/ssl/private/wildcard.my-site.de.key;
}

1 个答案:

答案 0 :(得分:1)

首先,我想在服务器块中分离不同的配置(即使现在相同,两年后回来时,您也会爱上自己,需要阅读此书)。

ssl证书:

Nginx在ssl_certificate下仅读取1个crt文件,在这里您需要将链和crt连接在同一文件中,更多信息:

https://futurestud.io/tutorials/how-to-configure-nginx-ssl-certifcate-chain

所以我要做的是:

为了安全起见,请勿触摸证书。

sudo cp /etc/ssl/private/wildcard.my-site.de.crt /etc/ssl/private/api-mysite-de.pem

并将您的链条连接到“证书”中。

sudo cat /etc/ssl/private/chain.crt > /etc/ssl/private/api-mysite-de.pem

然后,您可以将ssl_certificate设置为此文件,以使nginx正常工作。

server {

    listen 443 ssl;
    listen [::]:443 ipv6only=on ssl;

    server_name api.my-site.de
    ssl_on;
    ssl_certificate      /etc/ssl/private/api-mysite-de.pem;
    ssl_certificate_key  /etc/ssl/private/wildcard.my-site.de.key;

    access_log /var/log/nginx/ssl-api.my-site.de.access.log; 
    error_log /var/log/nginx/ssl-api.my-site.de.cat.error.log;


    location / {
        root   /var/www/api.my-site.de/current/public;
    }


}

这是http端口80的配置。

将您的.htaccess文件留在/var/www/api.my-site.de/current/public中,它应该可以正常工作。

server {
    listen 80;
    listen [::]:80 ipv6only=on;

    server_name api.my-site.de
    access_log /var/log/nginx/api.my-site.de.access.log; 
    error_log /var/log/nginx/api.my-site.de.cat.error.log;

    #logs are love, logs are life

    location / {
        root   /var/www/api.my-site.de/current/public;
    }

}

如果需要任何进一步的配置,或者在日志中显示了任何错误(我在此处配置了它们),我们将尝试处理它。

希望我能帮上忙。