0
1

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を使って同一サーバーで複数アプリを動かす

Posted at

Nginxを使って同一サーバーで複数アプリを動かす

何がしたい?

  • nginxとapacheを同一サーバーで共存させたい
  • node + expres.jsで作ったアプリをPathで振り分けたい

やりたいこと(例)

  • / にアクセスするとnginxにアクセス
  • /apache/ にアクセスすると、apacheにアクセス
  • /express/ にアクセスすると、express.jsで動かしているアプリにアクセス

やり方

  • nginxのリバースプロキシを使おう

インストール済

  • nginx
  • apache
  • node.js + npm + express.js

それぞれ単体では動かせるのを前提にしています。

動作方法(例)

  • apache
    • 8080 port で動作させる
  • express.js
    • 3000 port で動作させる

nginx.conf の設定

nginx.conf
user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    server_tokens off;	

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile on;
	
	server {
		listen 80;
		server_name localhost;
		
		root html;
		index index.html;
		
		location /apache/ {
			proxy_pass http://localhost:8080/;
		}

		location /express/ {
			proxy_pass http://localhost:3000/;
		}
	}
}

起動

アクセスできることを確認 :thumbsup:

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?