Nginxルーキーの自己進化

聞いたことはありますが、プロジェクトで使ったことがないので(ほとんどの場合、他の人がすでに設定しています)、nignxが魔法のようなものかどうかわかりません。

Nginxのインストール

1.Nginxと関連コンポーネントをダウンロードします

[root@master packages]# cd nginx-1.18.0
[root@master nginx-1.18.0]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  Makefile  man  objs  README  src
[root@master nginx-1.18.0]# 

c ++コンパイル環境をインストールします。すでにインストールされている場合は、スキップできます。

[root@localhost src]# yum install gcc-c++
省略安装内容...
期间会有确认提示输入y回车
Is this ok [y/N]:y

2.Nginxと関連コンポーネントをインストールします

opensslのインストール

[root@localhost src]# tar zxvf openssl-fips-2.0.10.tar.gz
省略安装内容...
[root@localhost src]# cd openssl-fips-2.0.10
[root@localhost openssl-fips-2.0.10]# ./config && make && make install
省略安装内容...

pcre install

[root@localhost src]# tar zxvf pcre-8.40.tar.gz
省略安装内容...
[root@localhost src]# cd pcre-8.40
[root@localhost pcre-8.40]# ./configure && make && make install
省略安装内容...

zlibのインストール

[root@localhost src]# tar zxvf zlib-1.2.11.tar.gz
省略安装内容...
[root@localhost src]# cd zlib-1.2.11
[root@localhost zlib-1.2.11]# ./configure && make && make install
省略安装内容...

nginxのインストール

[root@localhost src]# tar zxvf nginx-1.10.2.tar.gz
省略安装内容...
[root@localhost src]# cd nginx-1.10.2
[root@localhost nginx-1.10.2]# ./configure && make && make install
省略安装内容...

3.Nginxを起動します

まず、nginxがインストールされている場所を見つけます

[root@master nginx-1.18.0]# whereis nginx
nginx: /usr/local/nginx

nginxディレクトリに入り、開始します

[root@master nginx-1.18.0]# cd /usr/local/nginx/
[root@master nginx]# sbin/nginx 

ブラウザを開いてlocalhostと入力すると、次の画像が表示されます(私のnginxは仮想マシンで起動されたため、仮想マシンの静的ローカルエリアネットワークIPを入力しました)。これは、nginxが正常に起動したことを示しています。

nginxの基本操作

启动
[root@localhost ~]# /usr/local/nginx/sbin/nginx
停止/重启
[root@localhost ~]# /usr/local/nginx/sbin/nginx -s stop(quit、reload)
命令帮助
[root@localhost ~]# /usr/local/nginx/sbin/nginx -h
验证配置文件
[root@localhost ~]# /usr/local/nginx/sbin/nginx -t
配置文件
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf

4.Nginxの簡単な構成

nginxディレクトリの下のconfフォルダにあるnginx設定ファイルを開きます

[root@master nginx]# pwd
/usr/local/nginx
[root@master nginx]# cd conf/
[root@master conf]# vim nginx.conf

別のポート81を使用して、nginxを保存して終了し、再起動します

...

    server {
        listen          81;
        server_name     nginx.test.com;
        location / {
            root        html;
            index       index.html index.htm;
        }
    }

...
[root@master nginx]# sbin/nginx -s reload
[root@master nginx]# 

5.インターネットアクセスを開く

Linuxシステムでは、デフォルトでファイアウォールIptablesマネージャーのすべてのポートがあり、デフォルトのリモート接続ポート22のみが有効になっており、その他は閉じています。上記で設定した80なども閉じているため、開く必要があります。最初にアプリケーションポート。

独自の仮想マシンをテストする場合、ファイアウォールを直接オフにすることができます。これにより、パフォーマンスは向上しますが、セキュリティは低下します。フロントエンドファイアウォールを使用している場合は、次の方法を使用できます。

[root@master nginx]# service iptables stop
Redirecting to /bin/systemctl status iptables.service
Unit iptables.service could not be found.

ユニットが存在する場合、centos7の下にiptables.serviceが見つかりませんでした。エラーが報告された場合は、最初にiptables-servicesをインストールすることを忘れないでください。

[root@master nginx]# yum install iptables-services
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: mirrors.bfsu.edu.cn
[root@master nginx]# service iptables stop
Redirecting to /bin/systemctl stop iptables.service

ファイアウォールの他の操作コマンドは次のとおりです。

[root@master nginx]# service iptables start
[root@master nginx]# service iptables stop
[root@master nginx]# service iptables restart
[root@master nginx]# service iptables status

centos7 以后的话最好是用 systemctl
[root@slave nginx]# systemctl start firewalld
[root@slave nginx]# systemctl stop firewalld

Linuxの構成が完了しました。nginxがインストールされているコンピューターの代わりに別のコンピューターを使用してください。Windowsシステムを使用しています。ホストを構成します。「C:\ Windows \ System32 \ drivers \ etc」の下のホストでドメイン名のリダイレクトを構成します。 :

192.168.128.139 nginx.test.com

次に、cmdで再度pingを実行して、ドメイン名がこのIPを正しく指しているかどうかを確認します。

C:\Users\looking>ping nginx.test.com

正在 Ping nginx.test.com [192.168.128.139] 具有 32 字节的数据:
来自 192.168.128.139 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.128.139 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.128.139 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.128.139 的回复: 字节=32 时间<1ms TTL=64

192.168.128.139 的 Ping 统计信息:
    数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
    最短 = 0ms,最长 = 0ms,平均 = 0ms

正しくポイントした後、telnetのポート81をチェックして、ポートと通信できるかどうかを確認します(telnetがそのようなコマンドがないことを要求する場合、クライアントはインストールされていません。Windows機能を有効または無効にしてからインストールしてください)

C:\Users\lookinf>telnet 192.168.128.139 81 

次のインターフェースを取得すると、代表的なコミュニケーションが成功します

このWindowsシステムでブラウザを開き、nginx.test.comと入力すると、次の結果が得られます。これは、アクセスが成功したことを意味します。

ファイアウォールがまだ有効になっているが、ポートが有効になっている場合、ホワイトリストを追加していないため、ポート81にアクセスできないことがわかります。

この時点で、Nginxサーバールーキーチュートリアルのデプロイは完了です。

おすすめ

転載: blog.csdn.net/TomorrowAndTuture/article/details/111224672