CentOS 之 Nginx

1、安裝依賴包

# yum -y install gcc openssl-devel pcre-devel httpd-tools gcc-c++ wget vim tree

2、下載nginx

# wget http://nginx.org/download/nginx-1.10.2.tar.gz

3、解壓nginx

# tar xf nginx-1.10.2.tar.gz

4、進入nginx目錄

# cd nginx-1.10.2/

5、創(chuàng)建nginx用戶

# useradd nginx

6、檢查配置文件

# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module

如果安裝報錯:

./configure: error: the HTTP rewrite module requires the PCRE library.

# yum -y install pcre-devel openssl openssl-devel

7、編譯并安裝

# make && make install

8、建立快捷方式

# ln -s /usr/local/nginx/sbin/nginx /usr/sbin/

9、啟動nginx服務

# nginx

10、檢查nginx監(jiān)聽信息

# netstat -anptu | grep nginx

CentOS 7 命令變了:

# ss | grep nginx

11、修改配置

# vim /usr/local/nginx/conf/nginx.conf
# firewall-cmd --zone=public --add-port=80/tcp --permanent 
# firewall-cmd --reload

配置內容

worker_processes 1;
events {
? worker_connections 65535;
}
http {
? include mime.types;
? default_type application/octet-stream;
? sendfile on;
? keepalive_timeout 65;
? server {
? listen 80;
? server_name localhost;
? location / {
? root html;
? index index.html index.htm;
? }
? error_page 500 502 503 504 /50x.html;
? location = /50x.html {
? root html;
? }
?? }
}

12、刷新配置

# nginx -s reload #重啟nginx,刷新配置
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容