0
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

メモ:Exment on Lightsail + Docker(nginx)環境で、CORSするためのnginx.conf設定

Posted at

先日、Lightsail + Dockerという組み合わせで、ExmentというOSS WebDBシステムを構築したという話を書きました。

んで、その後にもExmentとMFクラウド請求書をAPIで組み合わせる記事も書きました。

で、両者の記事で大事なことを書き忘れていたんですね。

ExmentのAPIが通らない

Postmanでは通るんだけど、Node.jsで通らない。なぜだ… そうか、CORSか…

ということで、Exmentを運用しているDocker-composeはこちらなのですが、Webサーバーはnginxで動いています。

というわけで、nginx用のCORS設定を追記しました。

nginx.conf
server {
    listen 8080;
    server_name _;

    root  /var/www/exment/public;
    index index.php index.html;

    access_log /var/log/nginx/access.log;
    error_log  /var/log/nginx/error.log;

    location / {
        if ($request_method = 'OPTIONS') {
            add_header Access-Control-Allow-Origin '*';
            add_header Access-Control-Allow-Methods 'GET, POST, PUT, DELETE';
            add_header Access-Control-Allow-Headers 'Origin, Authorization, Accept, Content-Type';
            add_header Access-Control-Max-Age 3600;

            add_header Content-Type 'text/plain charset=UTF-8';
            add_header Content-Length 0;

            return 204;
         }

        try_files $uri /index.php?$query_string;
    }

    location ~ \.php$ {
        add_header Access-Control-Allow-Origin '*' always;
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include       fastcgi_params;
    }
}

0
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?