この記事は以下の記事の続きです。
#2 さくらインターネットVPS で CentOS7 + nginx + PHP7 + MySQL 「CentOS7 初期設定編」
次の記事はこちら
#4 さくらインターネットVPS で CentOS7 + nginx + PHP7 「PHP & MySQL編」
目次
1. nginxのインストール
1-1インストールする前にyumのリポジトリを登録する必要があります。
vim /etc/yum.repos.d/nginx.repo
ファイルが新規作成されました。
1-2
先程追加したファイルを以下のように記述します。baseurlのURLは他にもあるのですが、開発者がこのmainlineを勧めているのでここではmainlineのバージョンをインストールするようにします。
先程追加したファイルを以下のように記述します。baseurlのURLは他にもあるのですが、開発者がこのmainlineを勧めているのでここではmainlineのバージョンをインストールするようにします。
[nginx] name=nginx repo baseurl=http://nginx.org/packages/mainline/centos/7/$basearch/ gpgcheck=0 enabled=1
1-3さきほど追加したリポジトリからnginxをインストールします。
yum install nginx
1-4nginxを起動します。
systemctl start nginx
1-5nginxの状態の確認は以下でできます。
systemctl status nginx
[[email protected] chinpui]# systemctl status nginx ● nginx.service - nginx - high performance web server Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled) Active: active (running) since 日 2016-12-18 05:44:26 JST; 9s ago Docs: http://nginx.org/en/docs/ Process: 6471 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS) Process: 6469 ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS) Main PID: 6473 (nginx) CGroup: /system.slice/nginx.service ├─6473 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf └─6474 nginx: worker process
1-6このままだとOSの再起動時にnginxが自動的に起動しないのでサービスとして登録します。
systemctl enable nginx
[[email protected] chinpui]# systemctl enable nginx Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
最低限ですが、nginxの設定は以上ですが、CentOS7のfirewalldが働いているのでこのままだと外部からアクセスができません。
2. firewalldの設定
2-1HTTPでの外部からのアクセスを許可します。
firewall-cmd --permanent --add-service=http
[[email protected] chinpui]# firewall-cmd --permanent --zone=public --add-service=http success
2-2設定を有効にするため、firewalldをリロードします。
firewall-cmd --reload
[[email protected] chinpui]# firewall-cmd --reload success
2-3これで外部からHTTPによるアクセスが可能になりました。ブラウザからサーバーのIPをしてしてみるとnginxのWelcomeページが表示されるはずです。

2-4もしも表示されない場合にはfirewalld関連のコマンドを参考に状況を確認するといいでしょう。
firewalldの起動
systemctl start firewalld
firewalldの停止
systemctl stop firewalld
firewalldの自動起動設定の確認
systemctl is-enabled firewalld.service
firewalldの自動起動を設定(サービスに追加)
systemctl enable firewalld.service
firewalldを自動起動を停止(サービスの停止)
systemctl disable firewalld.service
firewalldのステータスの確認(現在の動作確認)
systemctl status firewalld
firewalldの設定の確認
firewall-cmd --list-all
続き↓
#4 さくらインターネットVPS で CentOS7 + nginx + PHP7 + MySQL 「PHP & MySQL編」