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

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

Jun 03, 2023 am 09:40 AM
linux 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

熱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

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

熱工具

記事本++7.3.1

記事本++7.3.1

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

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

vscode需要什麼電腦配置 vscode需要什麼電腦配置 Apr 15, 2025 pm 09:48 PM

VS Code 系統要求:操作系統:Windows 10 及以上、macOS 10.12 及以上、Linux 發行版處理器:最低 1.6 GHz,推薦 2.0 GHz 及以上內存:最低 512 MB,推薦 4 GB 及以上存儲空間:最低 250 MB,推薦 1 GB 及以上其他要求:穩定網絡連接,Xorg/Wayland(Linux)

Linux體系結構:揭示5個基本組件 Linux體系結構:揭示5個基本組件 Apr 20, 2025 am 12:04 AM

Linux系統的五個基本組件是:1.內核,2.系統庫,3.系統實用程序,4.圖形用戶界面,5.應用程序。內核管理硬件資源,系統庫提供預編譯函數,系統實用程序用於系統管理,GUI提供可視化交互,應用程序利用這些組件實現功能。

notepad怎麼運行java代碼 notepad怎麼運行java代碼 Apr 16, 2025 pm 07:39 PM

雖然 Notepad 無法直接運行 Java 代碼,但可以通過借助其他工具實現:使用命令行編譯器 (javac) 編譯代碼,生成字節碼文件 (filename.class)。使用 Java 解釋器 (java) 解釋字節碼,執行代碼並輸出結果。

git怎麼查看倉庫地址 git怎麼查看倉庫地址 Apr 17, 2025 pm 01:54 PM

要查看 Git 倉庫地址,請執行以下步驟:1. 打開命令行並導航到倉庫目錄;2. 運行 "git remote -v" 命令;3. 查看輸出中的倉庫名稱及其相應的地址。

vscode終端使用教程 vscode終端使用教程 Apr 15, 2025 pm 10:09 PM

vscode 內置終端是一個開發工具,允許在編輯器內運行命令和腳本,以簡化開發流程。如何使用 vscode 終端:通過快捷鍵 (Ctrl/Cmd ) 打開終端。輸入命令或運行腳本。使用熱鍵 (如 Ctrl L 清除終端)。更改工作目錄 (如 cd 命令)。高級功能包括調試模式、代碼片段自動補全和交互式命令歷史。

vscode在哪寫代碼 vscode在哪寫代碼 Apr 15, 2025 pm 09:54 PM

在 Visual Studio Code(VSCode)中編寫代碼簡單易行,只需安裝 VSCode、創建項目、選擇語言、創建文件、編寫代碼、保存並運行即可。 VSCode 的優點包括跨平台、免費開源、強大功能、擴展豐富,以及輕量快速。

VSCode怎麼用 VSCode怎麼用 Apr 15, 2025 pm 11:21 PM

Visual Studio Code (VSCode) 是一款跨平台、開源且免費的代碼編輯器,由微軟開發。它以輕量、可擴展性和對眾多編程語言的支持而著稱。要安裝 VSCode,請訪問官方網站下載並運行安裝程序。使用 VSCode 時,可以創建新項目、編輯代碼、調試代碼、導航項目、擴展 VSCode 和管理設置。 VSCode 適用於 Windows、macOS 和 Linux,支持多種編程語言,並通過 Marketplace 提供各種擴展。它的優勢包括輕量、可擴展性、廣泛的語言支持、豐富的功能和版

laravel安裝代碼 laravel安裝代碼 Apr 18, 2025 pm 12:30 PM

要安裝 Laravel,需依序進行以下步驟:安裝 Composer(適用於 macOS/Linux 和 Windows)安裝 Laravel 安裝器創建新項目啟動服務訪問應用程序(網址:http://127.0.0.1:8000)設置數據庫連接(如果需要)

See all articles