溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

nginx服務(wù)器搭建和配置的方法

發(fā)布時(shí)間:2022-04-28 14:02:07 來源:億速云 閱讀:268 作者:iii 欄目:大數(shù)據(jù)

這篇文章主要介紹“nginx服務(wù)器搭建和配置的方法”的相關(guān)知識(shí),小編通過實(shí)際案例向大家展示操作過程,操作方法簡單快捷,實(shí)用性強(qiáng),希望這篇“nginx服務(wù)器搭建和配置的方法”文章能幫助大家解決問題。

一、安裝編譯工具及庫文件

依賴庫安裝,一定要按照順序安裝:

(1) 如果沒有安裝c++編譯環(huán)境

 yum install gcc-c++

(2) ssl 功能需要 openssl 庫

wget https://www.openssl.org/source/openssl-1.1.0f.tar.gz
tar -zxvf openssl-1.1.0f.tar.gz
cd openssl-1.1.0f
./config make && make install

(3) rewrite 模塊需要 pcre 庫

wget https://ftp.pcre.org/pub/pcre/pcre-8.01.tar.gz
tar -zxvf pcre-8.01.tar.gz
cd pcre-8.01
./configure make && make install

(4) gzip 模塊需要 zlib 庫

wget https://nchc.dl.sourceforge.net/project/libpng/zlib/1.2.11/zlib-1.2.11.tar.gz
tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure make && make install

(4) nginx安裝

wget http://nginx.org/download/nginx-1.12.1.tar.gz
tar -zxvf nginx-1.12.1.tar.gz
cd nginx-1.12.1
./configure --prefix=/usr/local/nginx make && make install

二、設(shè)置依賴庫連接

如果輸入語句:./usr/local/nginx/sbin/nginx出現(xiàn)錯(cuò)誤:

error while loading shared libraries: libpcre.so.0: cannot open shared object file: no such file or directory

可輸入:

whereis libpcre.so.1

結(jié)果:libpcre.so: /lib64/libpcre.so.1 /usr/local/lib/libpcre.so /usr/local/lib/libpcre.so.0

再使用ln命令,將libpcre.so.0,libpcre.so和libpcre.so.1連接到lib64目錄下:

ln -s /usr/local/lib/libpcre.so.0 /lib64

三、nginx 配置

創(chuàng)建 nginx 運(yùn)行使用的用戶 www:

/usr/sbin/groupadd www
/usr/sbin/useradd -g www www

配置ngix.conf, 輸入:vi /usr/local/webserver/nginx/conf/nginx.conf的內(nèi)容修改為:

user www www;
worker_processes 2;

error_log ../error.log;
pid    /usr/local/nginx/nginx.pid;

worker_rlimit_nofile 65535;
events 
{
  use epoll;
  worker_connections 65535;
}


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

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

 server_names_hash_bucket_size 128;
 client_header_buffer_size 32k;
 large_client_header_buffers 4 32k;
 client_max_body_size 8m;

 sendfile on;
 tcp_nopush on;
 keepalive_timeout 60;
 tcp_nodelay on;
 fastcgi_connect_timeout 300;
 fastcgi_send_timeout 300;
 fastcgi_read_timeout 300;
 fastcgi_buffer_size 64k;
 fastcgi_buffers 4 64k;
 fastcgi_busy_buffers_size 128k;
 fastcgi_temp_file_write_size 128k;
 gzip on; 
 gzip_min_length 1k;
 gzip_buffers 4 16k;
 gzip_http_version 1.0;
 gzip_comp_level 2;
 gzip_types text/plain application/x-javascript text/css application/xml;
 gzip_vary on;
 server 
 {
    listen    80;//端口
    server_name localhost;//域名
    index test.html index.htm index.php;//解析網(wǎng)頁名稱
    root /usr/local/nginx/html; #站點(diǎn)目錄
  location ~ .*\.(php|php5)?$
  {
   #fastcgi_pass unix:/tmp/php-cgi.sock;
   fastcgi_pass 127.0.0.1:9000;
   fastcgi_index index.php;
   include fastcgi.conf;
  }

  location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|ico)$
  {
   expires 30d;
 # access_log off;
  }
  location ~ .*\.(js|css)?$
  {
   expires 15d;
  # access_log off;
  }
  access_log off;
 }

}

檢查配置是否正確:

/usr/local/webserver/nginx/sbin/nginx -t

啟動(dòng):/usr/local/webserver/nginx/sbin/nginx

監(jiān)聽進(jìn)程:ps -ef|grep nginx

訪問服務(wù)器ip: 192.168.1.23

nginx服務(wù)器搭建和配置的方法

問題:配置正確時(shí),也會(huì)出現(xiàn)ip地址無法訪問的情況:

可以通過阿里云服務(wù)器,esc服務(wù)器->安全組->配置規(guī)則->添加規(guī)則,進(jìn)行配置即可。

nginx服務(wù)器搭建和配置的方法

nginx服務(wù)器搭建和配置的方法

關(guān)于“nginx服務(wù)器搭建和配置的方法”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí),可以關(guān)注億速云行業(yè)資訊頻道,小編每天都會(huì)為大家更新不同的知識(shí)點(diǎn)。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI