CentOS7.X安裝Nginx
安裝nginx
-
安裝前的準備
yum install vim gcc gcc-c++ wget make libtool automake autoconf -y
-
安裝PCRE庫
cd /root wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz 或者(第三方):wget https://fossies.org/linux/misc/pcre-8.39.tar.gz tar -zxvf pcre-8.39.tar.gz cd pcre-8.39 ./configure make make install
-
安裝zlib庫
cd /root wget http://zlib.net/zlib-1.2.11.tar.gz tar -zxvf zlib-1.2.11.tar.gz cd zlib-1.2.11 ./configure make make install
-
安裝openssl
# openssl從1.0.2開始支援http2 cd /root wget https://www.openssl.org/source/openssl-1.0.2l.tar.gz tar -zxvf openssl-1.0.2l.tar.gz
-
安裝nginx
# nginx在1.9.5開始支援http2 cd /root wget http://nginx.org/download/nginx-1.13.2.tar.gz tar -zxvf nginx-1.13.2.tar.gz cd nginx-1.13.2 --------------------------------------------------------- # 安裝前小提示:如果要隱藏Web服務名稱`nginx`,可以使用以下方法 vim ./src/http/ngx_http_header_filter_module.c ngx_http_server_string[] = "Server: nginx" CRLF; # 改為 ngx_http_server_string[] = "Server: My web" CRLF; ESC :wq vim ./src/http/ngx_http_special_response.c <hr><center>nginx</center> # 改為 <center><h1>My web</h1></center> # 並且 static u_char ngx_http_msie_padding[] = "<!-- a padding to disable MSIE and Chrome friendly error page -->" CRLF "<!-- a padding to disable MSIE and Chrome friendly error page -->" CRLF "<!-- a padding to disable MSIE and Chrome friendly error page -->" CRLF "<!-- a padding to disable MSIE and Chrome friendly error page -->" CRLF "<!-- a padding to disable MSIE and Chrome friendly error page -->" CRLF "<!-- a padding to disable MSIE and Chrome friendly error page -->" CRLF; # 改為 static u_char ngx_http_msie_padding[] = "<!-- My web -->" CRLF; ESC :wq --------------------------------------------------------- ./configure --prefix=/usr/local/nginx/ --with-http_v2_module --with-http_ssl_module --with-http_realip_module --with-http_stub_status_module --with-pcre=../pcre-8.39/ --with-zlib=../zlib-1.2.11/ --with-openssl=../openssl-1.0.2l/ make make install
-
開啟80埠(方式1)
netstat -ano|grep 80 iptables -t filter -A INPUT -p tcp -j ACCEPT
-
開啟80埠(方式2)
yum install firewalld systemctl enable firewalld systemctl start firewalld firewall-cmd --zone=public --add-port=80/tcp --permanent firewall-cmd --zone=public --add-port=443/tcp --permanent firewall-cmd --reload
-
修改nginx配置
vim /usr/local/nginx/conf/nginx.conf user www; worker_processes auto; worker_cpu_affinity auto; pid logs/nginx.pid; events { worker_connections 1024; } http { charset utf-8; server_tokens off; include mime.types; default_type application/octet-stream; access_log logs/access.log; error_log logs/error.log; sendfile on; keepalive_timeout 65; gzip on; server { listen 80; server_name www.test.com; root /www; location / { index index.php index.html index.htm; } location ~ .php$ { fastcgi_index index.php; fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } } ESC :wq
-
如果沒有www使用者,建立www使用者
useradd www
-
啟動nginx並設定開機啟動
# 將nginx目錄所屬使用者設定為www mkdir /www chown -R www:www /www chown -R www:www /usr/local/nginx # 進入單元檔案目錄 cd /etc/systemd/system # 建立nginx單元檔案,格式為: [單元檔名].[單元檔案型別] vim nginx.service [Unit] Description=Start nginx on boot. After=network.target [Service] User=root Group=root Type=forking ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/usr/local/nginx/sbin/nginx -s reload ExecStop=/usr/local/nginx/sbin/nginx -s quit PrivateTmp=true [Install] WantedBy=multi-user.target ESC :wq # 修改檔案許可權為只有root使用者可以編輯該檔案 chown -R root:root /etc/systemd/system/nginx.service chmod -R 644 /etc/systemd/system/nginx.service # 更新systemd systemctl daemon-reload systemctl enable nginx systemctl start nginx
-
nginx操作
/usr/local/nginx/sbin/nginx 啟動 /usr/local/nginx/sbin/nginx -t 檢查當前配置錯誤 /usr/local/nginx/sbin/nginx -s reload 過載配置 /usr/local/nginx/sbin/nginx -s reopen 重開日誌 /usr/local/nginx/sbin/nginx -s quit 正常關閉 /usr/local/nginx/sbin/nginx -s stop 強制關閉
- 領支付寶紅包支援作者
相關文章
- CentOS7.X系統安裝CentOS
- CentOS7.X安裝elasticsearch-5.6.2CentOSElasticsearch
- Centos7.x環境下 安裝DiszzCentOS
- Centos7.X安裝DB210.5CentOSDB2
- CentOS7.X安裝postgresql-10.3CentOSSQL
- CentOS7.X安裝RabbitMQ-3.6.10CentOSMQ
- 【Nginx】Ubuntu 安裝 NginxNginxUbuntu
- [Nginx] Ubuntu 安裝 NginxNginxUbuntu
- Nginx 安裝Nginx
- 安裝nginxNginx
- nginx安裝Nginx
- CentOS7.X原始碼安裝MySQL-5.7.18CentOS原始碼MySql
- Mac 安裝 NginxMacNginx
- Nginx 安裝使用Nginx
- yum安裝nginxNginx
- mac安裝nginxMacNginx
- [LNMP]安裝NginxLNMPNginx
- (轉)Nginx安裝Nginx
- nginx-安裝Nginx
- Unbuntu nginx 安裝Nginx
- nginx ubuntu 安裝NginxUbuntu
- Docker安裝NginxDockerNginx
- zabbix安裝—–nginx安裝和配置Nginx
- 寶塔 Centos7.x安裝pdo_sqlsrv 擴充套件CentOSSQL套件
- 【推薦 - 原始碼安裝】nginx - 安裝原始碼Nginx
- Nginx安裝nginx-rtmp-module模組Nginx
- nginx原始碼安裝Nginx原始碼
- Nginx安裝與使用Nginx
- 使用docker安裝nginxDockerNginx
- Nginx安裝與代理Nginx
- CentOS 上安裝 NginxCentOSNginx
- docker下安裝NginxDockerNginx
- CentOS 7 - 安裝NginxCentOSNginx
- Centos 7 安裝NginxCentOSNginx
- Nginx安裝與配置Nginx
- 編譯安裝Nginx編譯Nginx
- nginx安裝及配置Nginx
- Nginx 原始碼安裝Nginx原始碼