ホームページ  >  記事  >  運用・保守  >  Linux で nginx をインストールして構成する方法

Linux で nginx をインストールして構成する方法

PHPz
PHPz転載
2023-05-23 23:22:043831ブラウズ

1. Linux で nginx をインストールして構成する

nginx を初めてインストールする場合、プロセス中に発生する問題は段階的に解決されます。

ツール securecrt は、サーバーに接続してログインするために使用されます。

1.1 rz コマンドを実行すると、ダイアログ ボックスが表示されるので、アップロードする nginx 圧縮パッケージを選択します。

#rz

1.2 解凍します

[root@vw010001135067 ~]# cd /usr/local/
[root@vw010001135067 local]# tar -zvxf nginx-1.10.2.tar.gz

1.3 nginx フォルダーに入り、./configure コマンドを実行します

[root@vw010001135067 local]# cd nginx-1.10.2
[root@vw010001135067 nginx-1.10.2]# ./configure

エラーは次のように報告されます:

checking for os
 + linux 2.6.32-431.el6.x86_64 x86_64
checking for c compiler ... not found

./configure: error: c compiler cc is not found

Thisエラーが発生します。その場合、gcc パッケージはインストールされません。

1.3.1 gcc のインストール

gcc の表示

[root@vw010001135067 nginx-1.10.2]# whereis gcc
gcc:

gcc のインストール

[root@vw010001135067 nginx-1.10.2]# yum -y install gcc

インストールが成功したら再度確認します

[root@vw010001135067 nginx-1.10.2]# whereis gcc
gcc: /usr/bin/gcc /usr/lib/gcc /usr/libexec/gcc /usr/share/man/man1/gcc.1.gz

gcc がインストールされています。

1.3.2 ./configure

[root@vw010001135067 nginx-1.10.2]# ./configure
checking for os
 + linux 2.6.32-431.el6.x86_64 x86_64
checking for c compiler ... found
......
checking for pcre library ... not found
checking for pcre library in /usr/local/ ... not found
checking for pcre library in /usr/include/pcre/ ... not found
checking for pcre library in /usr/pkg/ ... not found
checking for pcre library in /opt/local/ ... not found

./configure: error: the http rewrite module requires the pcre library.
you can either disable the module by using --without-http_rewrite_module
option, or install the pcre library into the system, or build the pcre library
statically from the source with nginx by using --with-pcre=<path> option.

を実行し続けると上記のエラーが発生します。 pcre-devel をインストールします

[root@vw010001135067 nginx-1.10.2]# yum install pcre-devel

1.3.3 ./configure を再度実行します

error: the http gzip module requires the zlib library.
you can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.

このエラーがある場合は実行してください

yum install zlib-devel

1.3.4 その後エラーは報告されません./configure

[root@vw010001135067 nginx-1.10.2]# ./configure
checking for os
 + linux 2.6.32-431.el6.x86_64 x86_64
checking for c compiler ... found
 + using gnu c compiler
 + gcc version: 4.4.7 20120313 (red hat 4.4.7-17) (gcc) 
.......
configuration summary
 + using system pcre library
 + openssl library is not used
 + md5: using system crypto library
 + sha1: using system crypto library
 + using system zlib library

 nginx path prefix: "/usr/local/nginx"
 nginx binary file: "/usr/local/nginx/sbin/nginx"
 nginx modules path: "/usr/local/nginx/modules"
 nginx configuration prefix: "/usr/local/nginx/conf"
 nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
 nginx pid file: "/usr/local/nginx/logs/nginx.pid"
 nginx error log file: "/usr/local/nginx/logs/error.log"
 nginx http access log file: "/usr/local/nginx/logs/access.log"
 nginx http client request body temporary files: "client_body_temp"
 nginx http proxy temporary files: "proxy_temp"
 nginx http fastcgi temporary files: "fastcgi_temp"
 nginx http uwsgi temporary files: "uwsgi_temp"
 nginx http scgi temporary files: "scgi_temp"

1.4 の実行 openssl 機能、sha1 機能を使用する場合。次に、openssl をインストールし、sha1

[root@vw010001135067 nginx-1.10.2]# yum install openssl openssl-devel 
[root@vw010001135067 nginx-1.10.2]# install perl-digest-sha1.x86_64

1.4.1 ssl モジュールを有効にして、./configure –with-http_ssl_module

[root@vw010001135067 nginx-1.10.2]# ./configure --with-http_ssl_module

1.4.2 を実行します。「サーバー ステータス」ページを有効にして、./configure を実行します。 –with -http_stub_status_module

[root@vw010001135067 nginx-1.10.2]# ./configure --with-http_stub_status_module

上記 2 つのコマンドを同時に開始できます

コードをコピーしますコードは次のとおりです:


[root@vw010001135067 nginx-1.10.2]# ./configure --with-http_stub_status_module --with-http_ssl_module

1.5 上記のconfigureは成功しました

makeコマンドを実行し、make installコマンドを実行します。

[root@vw010001135067 nginx-1.10.2]# make
[root@vw010001135067 nginx-1.10.2]# make install

この時点で、nginx は成功します。

1.6 環境変数を設定します

/etc/profile に設定を追加します

設定ファイルを開きます

[root@vw010001135067 nginx-1.10.2]# vi /etc/profile

設定ファイルに追加

#nginx configure
export nginx_home=/usr/local/nginx-1.10.2
export path=$path:$nginx_home/sbin

上記のように入力し始めましたが、nginx -vを使用すると見つかりませんでした。上記の nginx_home 設定のアドレスが間違っていることに気付きました。まずnginxのインストールアドレスを探します

[root@vw010001135067 nginx-1.10.2]# whereis nginx
nginx: /usr/local/nginx

これは本当に間違ったアドレスです 上記を

#nginx configure
export nginx_home=/usr/local/nginx
export path=$path:$nginx_home/sbin

に変更します コンパイル後、保存して終了し、

[root@vw010001135067 nginx-1.10.2]# source /etc/profile

を実行して設定を行います効果的。

1.7 nginx バージョンの確認

[root@vw010001135067 nginx]# nginx -v
nginx version: nginx/1.10.2

プロセス全体が成功しました。

2. nginx.conf を変更します

2.1 nginx を開始します

設定後の nginx サービスは http://10.1.135.67/ にあります。成功しました。nginx

[root@vw010001135067 nginx]# cd /usr/local/nginx
[root@vw010001135067 nginx]# nginx -c conf/nginx.conf

を起動してください。起動が成功しました。ブラウザで http://10.1.135.67/ を開きます。デフォルトのポート番号は 80.

Linux で nginx をインストールして構成する方法

です。

上記のように、nginx はすでに正常に動作しています。

2.2 Tomcat サービスの構成

現在、Tomcat サービスは 10.1.29.15 にあり、nginx 経由で転送する必要があります。次に、nginx.conf を開いて構成ファイルを変更します。次のように追加します:

#user nobody;
worker_processes 1;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid  logs/nginx.pid;


events {
 worker_connections 1024;#最大连接数,默认为512
 accept_mutex on; #设置网路连接序列化,防止惊群现象发生,默认为on
 multi_accept on; #设置一个进程是否同时接受多个网络连接,默认为off
 #use epoll;  #事件驱动模型,select|poll|kqueue|epoll|resig|/dev/poll|eventport 
}


http {
 #文件扩展名与文件类型映射表
 include  mime.types;

 #默认文件类型,默认为text/plain 
 default_type application/octet-stream;

 #自定义格式
 log_format main &#39;$remote_addr - $remote_user [$time_local] "$request" &#39;
      &#39;$status $body_bytes_sent "$http_referer" &#39;
      &#39;"$http_user_agent" "$http_x_forwarded_for"&#39;; 

 #combined为日志格式的默认值
 access_log logs/access.log main;

 #允许sendfile方式传输文件,默认为off,可以在http块,server块,location块
 sendfile  on;
 sendfile_max_chunk 100k; #每个进程每次调用传输数量不能大于设定的值,默认为0,即不设上限。

 #tcp_nopush  on;

 #连接超时时间,默认为75s,可以在http,server,location块。
 keepalive_timeout 65;

 #gzip on;

 upstream upload {
  server 10.1.29.15:8080;
 }

 error_page 404 https://www.baidu.com; #错误页

 server {
  keepalive_requests 120; #单连接请求上限次数。
  listen  80; #监听端口
  server_name localhost; #监听地址 

  #charset koi8-r;

  #access_log logs/host.access.log main;

  location ~ ^.*?/upload/[^/]*?$ {
   proxy_connect_timeout 15;
   proxy_send_timeout 15;
   proxy_read_timeout 15;
   proxy_set_header host $host;
   proxy_set_header x-real-ip $remote_addr;
   proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;
   proxy_set_header connection "";
   proxy_pass http://upload; #请求转向upload 定义的服务器列表
   client_max_body_size 1024m;
} 
 }
}

設定後、設定ファイルを保存してnginxを再起動します

[root@vw010001135067 nginx]# nginx -s reload

アップロード プロジェクトがブラウザで正常に呼び出されるかどうか

Linux で nginx をインストールして構成する方法

# 図に示すように、プロジェクトに正しくアクセスでき、構成は成功しました。

以上がLinux で nginx をインストールして構成する方法の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

声明:
この記事はyisu.comで複製されています。侵害がある場合は、admin@php.cn までご連絡ください。