12
13

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 5 years have passed since last update.

nginxでリバースプロキシ

Last updated at Posted at 2016-01-15

準備

  • ubuntu 16.04、nginx 1.9.9 で確認
インストール
apt-get install -y nginx
初期設定を編集したくないので削除。
rm /etc/nginx/sites-enabled/default
/etc/nginx/sites-available/proxy
server {
    listen 80;
    server_name _; # バーチャルホスト

    root /var/www/html;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }

    location /node/ {
        proxy_pass http://localhost:4000/;
    }
}
反映
ln -s /etc/nginx/sites-{available,enabled}/proxy
service nginx restart

アクセス制限

/etc/nginx/sites-available/proxy
 server {
     listen 80;
     server_name _;
 
     root /var/www/html;
     index index.html;

     location / {
         try_files $uri $uri/ =404;
     }
 
     location /node/ {
         proxy_pass http://localhost:4000/;
+        allow 127.0.0.1/32;
+        deny all;
     }
 }

アクセス拒否したログは以下となる。(/var/log/nginx/error.log)

2016/01/15 09:46:58 [error] 28028#28028: *1 access forbidden by rule, client: 192.168.0.30, server: _, request: "GET /node/ HTTP/1.1", host: "192.168.0.2"

12
13
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
12
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?