nginx 如何处理请求系列1-Nginx安装
2019獨角獸企業重金招聘Python工程師標準>>>
一些準備工作,常見問題
簡介
Nginx (engine x) 是一個高性能的HTTP和反向代理服務器,也是一個IMAP/POP3/SMTP服務器,其將源代碼以類BSD許可證的形式發布。現在Nginx已經成為一家擁有各種產品的公司,包括Nginx Plus、Nginx Ctroller、 Nginx Unit、 Nginx Amplify、 Nginx WAF.但是Nginx仍然是開源。整個系列都會依托開源的版本,簡稱Nginx
安裝
兩類安裝,官方編譯好的安裝包直接通過源安裝即可,二是通過源碼包編譯安裝。 編譯好的安裝包已經加入依賴關系解決,不用用戶自己處理依賴不存在對的情況。源碼包安裝提供更高的定制性,可最大化性能或功能。
官方編譯好的安裝包 這里我們使用centos6.x系統
[root@slave2 ~]# vim /etc/yum.repos.d/nginx.repo name=nginx repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=0 enabled=1[root@slave2 ~]# yum install nginx -y Installed:nginx.x86_64 0:1.12.2-1.el6.ngx Complete![root@slave2 ~]# nginx nginx nginx-debug[root@slave2 ~]# which nginx /usr/sbin/nginx [root@slave2 ~]# which nginx-debug /usr/sbin/nginx-debug [root@slave2 ~]# /usr/sbin/nginx -V nginx version: nginx/1.12.2 built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC) built with OpenSSL 1.0.1e-fips 11 Feb 2013 TLS SNI support enabled configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' [root@slave2 ~]# /usr/sbin/nginx-debug -V nginx version: nginx/1.12.2 built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC) built with OpenSSL 1.0.1e-fips 11 Feb 2013 TLS SNI support enabled configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' --with-debugnginx安裝后加入nginx和nginx-debug命令,nginx-debug比nginx編譯參數多了--with-debug開啟了debug日志,這在調試nginx時十分有用,但開啟后會嚴重限制nginx的并發數。
編譯安裝
[root@slave2 ~]# wget http://nginx.org/download/nginx-1.12.2.tar.gz [root@slave2 ~]# tar -zxvf nginx-1.12.2.tar.gz [root@slave2 ~]# cd nginx-1.12.2 [root@slave2 nginx-1.12.2]# ./configure --prefix=/opt/nginx-1.12.2 --with-debug [root@slave2 nginx-1.12.2]# make -j2 [root@slave2 nginx-1.12.2]# make install源碼包需要自己解決依賴關系~~
管理nginx
安裝包
[root@slave2 ~]# /etc/init.d/nginx start Starting nginx: [ OK ] [root@slave2 ~]# /etc/init.d/nginx reload Starting nginx: [ OK ] [root@slave2 ~]# /etc/init.d/nginx stop Stopping nginx: [ OK ]debug版本
[root@slave2 ~]# /etc/init.d/nginx-debug start Starting nginx: [ OK ] [root@slave2 ~]# /etc/init.d/nginx-debug reload Starting nginx: [ OK ] [root@slave2 ~]# /etc/init.d/nginx-debug stop Stopping nginx: [ OK ]源碼包
[root@slave2 ~]# /opt/nginx-1.12.2/sbin/nginx [root@slave2 ~]# /opt/nginx-1.12.2/sbin/nginx -s reload [root@slave2 ~]# /opt/nginx-1.12.2/sbin/nginx -s stop [root@slave2 ~]# /opt/nginx-1.12.2/sbin/nginx -t nginx: the configuration file /opt/nginx-1.12.2/conf/nginx.conf syntax is ok nginx: configuration file /opt/nginx-1.12.2/conf/nginx.conf test is successful測試
[root@slave2 ~]# curl localhost <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style>body {width: 35em;margin: 0 auto;font-family: Tahoma, Verdana, Arial, sans-serif;} </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p><p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p><p><em>Thank you for using nginx.</em></p> </body> </html>默認nginx監聽在localhost上,通過curl訪問成功。 nginx已經安裝成功。如果提示如下,請檢查防火墻是否開放80端口訪問。
[root@slave2 ~]# curl localhost curl: (7) couldn't connect to host轉載于:https://my.oschina.net/monkeyzhu/blog/1649573
總結
以上是生活随笔為你收集整理的nginx 如何处理请求系列1-Nginx安装的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 初探 es6 promise
- 下一篇: 墨菲的鬼魂重现 / 金蝶ERP 资安大漏