關于nginx的相關介紹我就不說了,既然你選擇nginx作為你的web服務器,想必你多少也對nginx server有不同認知和理解,接下來我就直接安裝。
1.先決條件:
我使用的是centos7.3 64位核心版系統,安裝配置nginx前必須安裝nginx依賴包,請查看;Centos 7編譯安裝php7.1之生產篇,并安裝前文開頭所提供的依賴包。此依賴組件包適用于Nginx任意版本。
新建web用戶和組
1
2
3
|
$ /usr/sbin/groupadd www $ /usr/sbin/useradd -g www www $ ulimit -SHn 65535 //設置linux高負載參數 |
2.從官方下載Nginx以及OpenSSL
下載Nginx時有兩個版本:開發版和穩定版,如果用于生產就下載穩定版本,http://nginx.org/en/download.html (最好下載最新版本的穩定版,這樣會有bug修復以及新特性)我下載的是就是目前最新版本nginx-1.13.5。
1
2
3
4
5
6
|
$ cd /tmp $ wget https: //www .openssl.org /source/openssl-1 .1.0e. tar .gz $ tar zxvf openssl-1.1.0e. tar .gz $ wget https: //nginx .org /download/nginx-1 .13.5. tar .gz $ tar zxvf nginx-1.13.5. tar .gz $ cd nginx-1.13.5 |
3.安裝Nginx
你可能會注意到有些文檔教程安裝nginx的時候,并未指派這么多模塊,(看起來好長),有的連模塊和用戶都沒有指派,其實模塊是根據自己的需要指派的, 如果想以后不麻煩,那么就按照下面的模塊指派就行了,其實這也算是全能的了,不然后期你需要什么還得重新編譯進去,不是很麻煩,但也不省事。至于是否指派用戶組,我堅決會讓你指派,這可關乎nginx配置的可用性和安全穩定。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
$ ./configure --prefix=/usr/local/nginx --user=www --group=www --with-pcre --with-openssl=/tmp/openssl-1.1.0e --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-http_image_filter_module --with-http_slice_module --with-mail --with-threads --with-file-aio --with-stream --with-mail_ssl_module --with-stream_ssl_module |
1
|
$ make -j8 && make install //編譯并安裝 |
4.創建 systemctl 系統 Nginx 單元文件
安裝完成后還需要開機自啟動,不然每次開機都需要手動,那豈不是太麻煩。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
$ vim /usr/lib/systemd/system/nginx.service [Unit] Description=The nginx HTTP and reverse proxy server After=syslog.target network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=/usr/local/nginx/logs/nginx.pid ExecStartPre=/usr/local/nginx/sbin/nginx -t ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/bin/kill -s HUP /usr/local/nginx/logs/nginx.pid ExecStop=/bin/kill -s QUIT /usr/local/nginx/logs/nginx.pid PrivateTmp=true [Install] WantedBy=multi-user.target |
保存并退出。
5.加入開機自啟動并啟動Nginx
1
2
|
$ systemctl enable nginx.service $ systemctl restart nginx.service |
6.設置Firewalld防火墻
1
2
|
$ firewall-cmd --zone=public --add-port=80/tcp --permanent $ firewall-cmd --reload |
7.查看Nginx是否啟動成功
1
|
$ ss -ntlp |
可以查看到nginx進程已經運行了。到此nginx安裝就完成了,可能你還會有疑問,nginx怎么解析并支持php程序呢,別慌,下一篇文章中我會寫到。
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。
原文鏈接:https://renwole.com/archives/39