搜尋
首頁運維NginxLinux伺服器下該怎麼安裝設定Nginx

nginx 安裝

一、安裝編譯工具及程式庫檔案

yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel

二、首先要安裝pcre

#pcre 作用是讓nginx 支援rewrite 功能。

1、下載pcre 安裝包,下載位址:

[root@bogon src]# wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz

Linux伺服器下該怎麼安裝設定Nginx

#2、解壓縮安裝包:

[root@bogon src]# tar zxvf pcre-8.35.tar.gz

3、進入安裝包目錄

[root@bogon src]# cd pcre-8.35

4、編譯安裝

[root@bogon pcre-8.35]# ./configure
[root@bogon pcre-8.35]# make && make install

5、查看pcre版本

[root@bogon pcre-8.35]# pcre-config --version

Linux伺服器下該怎麼安裝設定Nginx

三、安裝nginx

1、下載nginx,下載位址:

[root@bogon src]# wget http://nginx.org/download/nginx-1.6.2.tar.gz

Linux伺服器下該怎麼安裝設定Nginx

2、解壓縮安裝套件

[root@bogon src]# tar zxvf nginx-1.6.2.tar.gz

3、進入安裝套件目錄

[root@bogon src]# cd nginx-1.6.2

4、編譯安裝

[root@bogon nginx-1.6.2]# ./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35
[root@bogon nginx-1.6.2]# make
[root@bogon nginx-1.6.2]# make install

5、查看nginx版本

[root@bogon nginx-1.6.2]# /usr/local/webserver/nginx/sbin/nginx -v

Linux伺服器下該怎麼安裝設定Nginx

到此,nginx安裝完成。

四、nginx 設定

建立nginx 運行使用的使用者www:

[root@bogon conf]# /usr/sbin/groupadd www 
[root@bogon conf]# /usr/sbin/useradd -g www www

配置nginx.conf ,將/usr/local/webserver/ nginx/conf/nginx.conf替換為以下內容

[root@bogon conf]# cat /usr/local/webserver/nginx/conf/nginx.conf
user www www;
worker_processes 2; #设置值和cpu核心数一致
error_log /usr/local/webserver/nginx/logs/nginx_error.log crit; #日志位置和日志级别
pid /usr/local/webserver/nginx/nginx.pid;
#specifies the value for maximum file descriptors that can be opened by this process.
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';
#charset gb2312;
 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;
 #limit_zone crawler $binary_remote_addr 10m;
 #下面是server虚拟主机的配置
 server
 {
 listen 80;#监听端口
 server_name localhost;#域名
 index index.html index.htm index.php;
 root /usr/local/webserver/nginx/html;#站点目录
 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;
 }
}

檢查設定檔ngnix.conf的正確性指令:

[root@bogon conf]# /usr/local/webserver/nginx/sbin/nginx -t

##、啟動nginx

#nginx 啟動指令如下:

[root@bogon conf]# /usr/local/webserver/nginx/sbin/nginx

Linux伺服器下該怎麼安裝設定Nginx

#六、造訪網站

從瀏覽器造訪我們設定的網站ip:

Linux伺服器下該怎麼安裝設定Nginx

七、nginx 其他指令

#以下包含了nginx 常用的幾個指令:

/usr/local/webserver/nginx/sbin/nginx -s reload  # 重新载入配置文件
/usr/local/webserver/nginx/sbin/nginx -s reopen  # 重启 nginx
/usr/local/webserver/nginx/sbin/nginx -s stop  # 停止 nginx

以上是Linux伺服器下該怎麼安裝設定Nginx的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述
本文轉載於:亿速云。如有侵權,請聯絡admin@php.cn刪除
NGINX的優點:速度,效率和控制NGINX的優點:速度,效率和控制May 12, 2025 am 12:13 AM

NGINX受歡迎的原因是其在速度、效率和控制方面的優勢。 1)速度:採用異步、非阻塞處理,支持高並發連接,靜態文件服務能力強。 2)效率:內存使用低,負載均衡功能強大。 3)控制:通過靈活的配置文件管理行為,模塊化設計便於擴展。

NGINX與Apache:社區,支持和資源NGINX與Apache:社區,支持和資源May 11, 2025 am 12:19 AM

NGINX和Apache在社區、支持和資源方面的差異如下:1.NGINX的社區雖然規模較小,但活躍度和專業性高,官方支持通過NGINXPlus提供高級功能和專業服務。 2.Apache擁有龐大且活躍的社區,官方支持主要通過豐富的文檔和社區資源提供。

NGINX單元:應用程序服務器簡介NGINX單元:應用程序服務器簡介May 10, 2025 am 12:17 AM

NGINXUnit是一個開源的應用服務器,支持多種編程語言和框架,如Python、PHP、Java、Go等。 1.它支持動態配置,可以在不重啟服務器的情況下調整應用配置。 2.NGINXUnit支持多語言應用,簡化了多語言環境的管理。 3.通過配置文件,可以輕鬆部署和管理應用,如運行Python和PHP應用。 4.它還支持高級配置,如路由和負載均衡,幫助管理和擴展應用。

使用NGINX:優化網站性能和可靠性使用NGINX:優化網站性能和可靠性May 09, 2025 am 12:19 AM

NGINX可通过以下方式提升网站性能和可靠性:1.作为Web服务器处理静态内容;2.作为反向代理服务器转发请求;3.作为负载均衡器分配请求;4.作为缓存服务器减轻后端压力。通过配置优化如启用Gzip压缩和调整连接池,NGINX能显著提高网站性能。

NGINX的目的:服務Web內容等NGINX的目的:服務Web內容等May 08, 2025 am 12:07 AM

nginxserveswebcontentandactsasareverseproxy,loadBalancer和more.1)效率高效的servesstaticContentLikeHtmlandImages.2)itfunctionsasareverseproxybalancer,and andginxenhanceperforfforfforfforfforfforffrenfcaching.4)

NGINX單元:簡化應用程序部署NGINX單元:簡化應用程序部署May 07, 2025 am 12:08 AM

NGINXUnit通過動態配置和多語言支持簡化應用部署。 1)動態配置無需重啟服務器即可修改。 2)支持多種編程語言,如Python、PHP、Java。 3)採用異步非阻塞I/O模型,提升高並發處理性能。

NGINX的影響:Web服務器及其他NGINX的影響:Web服務器及其他May 06, 2025 am 12:05 AM

NGINX起初解決C10K問題,現已發展為處理負載均衡、反向代理和API網關的全能選手。 1)它以事件驅動和非阻塞架構聞名,適合高並發。 2)NGINX可作為HTTP和反向代理服務器,支持IMAP/POP3。3)其工作原理基於事件驅動和異步I/O模型,提升了性能。 4)基本用法包括配置虛擬主機和負載均衡,高級用法涉及復雜負載均衡和緩存策略。 5)常見錯誤包括配置語法錯誤和權限問題,調試技巧包括使用nginx-t命令和stub_status模塊。 6)性能優化建議包括調整worker參數、使用gzip壓縮和

NGINX故障排除:診斷和解決常見錯誤NGINX故障排除:診斷和解決常見錯誤May 05, 2025 am 12:09 AM

Nginx常見錯誤的診斷與解決方法包括:1.查看日誌文件,2.調整配置文件,3.優化性能。通過分析日誌、調整超時設置和優化緩存及負載均衡,可以有效解決404、502、504等錯誤,提高網站穩定性和性能。

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

VSCode Windows 64位元 下載

VSCode Windows 64位元 下載

微軟推出的免費、功能強大的一款IDE編輯器

WebStorm Mac版

WebStorm Mac版

好用的JavaScript開發工具

mPDF

mPDF

mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

將Eclipse與SAP NetWeaver應用伺服器整合。

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器