LoginSignup
3
3

More than 5 years have passed since last update.

俺なりのNginxとhttpdの新婚生活

Last updated at Posted at 2016-07-13

前書き

nginxとapacheを共存させるための備忘録です。

うざい記事ですがよろしくお願いします。

自己紹介

大阪を拠点に活動しているフロントエンドエンジニアです。HAL大阪2年生です。

Twitterやってます。

@konojunya

新婚生活の登場人物

nginxくんとhttpdちゃん。

生活の場所

centosという名のエデン

Nginxくん

yumなどでinstallしてください。

.confファイルを書き足します。

$ vim /etc/nginx/conf.d/hoge.conf

中身はこんな感じ

server {
    listen 80;
    server_name  hoge.com;

    location / {
            proxy_pass http://localhost:<portを指定>;

            proxy_redirect                          off;
            proxy_set_header Host                   $host;
            proxy_set_header X-Real-IP              $remote_addr;
            proxy_set_header X-Forwarded-Host       $host;
            proxy_set_header X-Forwarded-Server     $host;
            proxy_set_header X-Forwarded-For        $proxy_add_x_forwarded_for;
    }
}

ここまできたらnginxを立ち上げます。

$ sudo service nginx start

httpdちゃん

同じくyumなどでinstallしてください。

.confファイルを書き足します。

$ vim /etc/httpd/conf.d/hoge.conf

中身はこんな感じ

<VirtualHost *:<さっき指定したport>>
  ServerName hoge.com
  DocumentRoot "/var/www/hoge"
  DirectoryIndex index.html index.php
  AdddefaultCharset UTF-8
  <Directory "/var/www/hoge">
    AllowOverride All
  </Directory>
</VirtualHost>

書いたら次はhttpd.confを書き換えます。

$ vim /etc/httpd/conf/httpd.conf

3か所ほどいじります。

1 - Listenを変えよう。

Listenを8080に変えましょう。

# prevent Apache from glomming onto all bound IP addresses (0.0.0.0)
#
#Listen 12.34.56.78:80
Listen 80 これを
Listen 8080 こうする

#
# Dynamic Shared Object (DSO) Support
#
# To be able to use the functionality of a module which was built as a DSO you

2 - DocumentRootを変えよう。

DocumentRootを/var/www/htmlになっているのを/var/wwwにかえる
(ここはもしかしたらしなくてもいいかもしれないです。)

# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/var/www/html" ここを
DocumentRoot "/var/www" こうする
#
# Each directory to which Apache has access can be configured with respect
# to which services and features are allowed and/or disabled in that

3 - NameVirtualHostを変えよう。

NameVirtualHostを8080に変えましょう

#
# Use name-based virtual hosting.
#
NameVirtualHost *:80 ここを
NameVirtualHost *:8080 にしましょう
#
# NOTE: NameVirtualHost cannot be used without a port specifier
# (e.g. :80) if mod_ssl is being used, due to the nature of the

これであとはhttpdを動かせば、もう二人はメロメロなわけです。

$ sudo service httpd start

新婚さんファイトです( ´ ▽ ` )ノ

3
3
1

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
3
3