Linux下nginx的安裝
安裝環境:
# cat /proc/version
Linux version 3.10.0-123.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.2 20140120 (Red Hat 4.8.2-16) (GCC) ) #1 SMP Mon Jun 30 12:09:22 UTC 2014
# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
yum安裝
- 設定yum倉庫地址
vi /etc/yum.repos.d/nginx.repo:
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
- 使用yum安裝:
# yum install -y nginx
安裝完成后組態檔所在目錄為/etc/nginx,
- nginx的啟動與停止:
- 啟動nginx:
nginx或systemctl start nginx, - 停止nginx:
nginx -s stop或systemctl stop nginx,
- 查看nginx是否啟動成功,
# ps -ef|grep nginx
root 1830 1 0 22:45 ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx 1831 1830 0 22:45 ? 00:00:00 nginx: worker process
root 1835 1638 0 22:45 pts/0 00:00:00 grep --color=auto nginx
# systemctl status nginx
● nginx.service - nginx - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
Active: active (running) since Wed 2020-10-07 22:45:12 EDT; 22s ago
Docs: http://nginx.org/en/docs/
Process: 1817 ExecStop=/bin/kill -s TERM $MAINPID (code=exited, status=1/FAILURE)
Process: 1829 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
CGroup: /system.slice/nginx.service
├─1830 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
└─1831 nginx: worker process
Oct 07 22:45:12 localhost.localdomain systemd[1]: Starting nginx - high performance web server...
Oct 07 22:45:12 localhost.localdomain systemd[1]: Can't open PID file /var/run/nginx.pid (yet?) after start: No such file or directory
Oct 07 22:45:12 localhost.localdomain systemd[1]: Started nginx - high performance web server.
-
訪問網站
http://localhost/, -
卸載nginx,
# yum list nginx
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.ustc.edu.cn
* centos-sclo-rh: mirrors.163.com
* centos-sclo-sclo: mirrors.ustc.edu.cn
* extras: mirrors.ustc.edu.cn
* updates: mirrors.ustc.edu.cn
Installed Packages
nginx.x86_64 1:1.18.0-1.el7.ngx @nginx-stable
# yum remove nginx.x86_64
Loaded plugins: fastestmirror
... ...
原始碼安裝
原始碼安裝的方式方便對nginx進行自定義的配置以及安裝插件,
-
下載原始碼,下載地址:http://nginx.org/en/download.html,這里使用的版本為
nginx-1.18.0.tar.gz, -
解壓
nginx-1.18.0.tar.gz:
# tar xf nginx-1.18.0.tar.gz
- 安裝可能需要的依賴:
# yum -y install autoconf automake make
# yum -y install gcc gcc-c++
# yum -y install pcre pcre-devel
# yum -y install zlib zlib-devel
# yum install -y openssl openssl-devel
- 配置:
# cd nginx-1.18.0
# ./configure
- 安裝:
# make && make install
安裝完成后的二進制檔案和組態檔在/usr/local/nginx目錄下,
- 配置環境變數:
# vi /etc/profile
最后增加 export PATH=$PATH:/usr/local/nginx/sbin
# source /etc/profile
- 安裝成為服務:
# vi nginx.service
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/usr/local/nginx/sbin/nginx -s stop
[Install]
WantedBy=multi-user.target
# systemctl daemon-reload
OpenResty的安裝
OpenResty是一個基于Nginx與Lua的高性能Web平臺,其內部集成了大量精良的Lua庫、第三方模塊以及大多數的依賴項,
-
下載OpenResty,下載地址:
https://openresty.org/download/openresty-1.17.8.2.tar.gz, -
安裝:
# tar xf openresty-1.17.8.2.tar.gz
# cd openresty-1.17.8.2
# ./configure
# make && make install
- 配置環境變數:
# vi /etc/profile
最后追加 export PATH=$PATH:/usr/local/openresty/bin
# cd /usr/local/openresty/bin
# ll | grep openresty
lrwxrwxrwx. 1 root root 37 Oct 9 14:09 openresty -> /usr/local/openresty/nginx/sbin/nginx
openresty是一個指向/usr/local/openresty/nginx/sbin/nginx的軟鏈接,其實openresty內置了一個nginx,使用方法與nginx一樣,
# openresty -V
nginx version: openresty/1.17.8.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/openresty/nginx --with-cc-opt=-O2 --add-module=../ngx_devel_kit-0.3.1 --add-module=../echo-nginx-module-0.62 --add-module=../xss-nginx-module-0.06 --add-module=../ngx_coolkit-0.2 --add-module=../set-misc-nginx-module-0.32 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.08 --add-module=../srcache-nginx-module-0.32 --add-module=../ngx_lua-0.10.17 --add-module=../ngx_lua_upstream-0.07 --add-module=../headers-more-nginx-module-0.33 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.19 --add-module=../redis2-nginx-module-0.15 --add-module=../redis-nginx-module-0.3.7 --add-module=../rds-json-nginx-module-0.15 --add-module=../rds-csv-nginx-module-0.09 --add-module=../ngx_stream_lua-0.0.8 --with-ld-opt=-Wl,-rpath,/usr/local/openresty/luajit/lib --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_ssl_module
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/168536.html
標籤:其他
上一篇:Linux - CentOS 寶塔管理面板的安裝與配置管理(Windows)
下一篇:2006-京淘Day09
