本篇內(nèi)容介紹了“Linux環(huán)境下怎么安裝及使用Nginx”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠?qū)W有所成!
創(chuàng)新互聯(lián)建站主要從事成都網(wǎng)站設計、網(wǎng)站建設、外貿(mào)網(wǎng)站建設、網(wǎng)頁設計、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務。立足成都服務洪洞,十余年網(wǎng)站建設經(jīng)驗,價格優(yōu)惠、服務專業(yè),歡迎來電咨詢建站服務:18982081108
一、查看centos的版本
cat /etc/redhat-release
二、添加資源庫
在 centos 系統(tǒng)上安裝 nginx ,得先去添加一個資源庫:
vim /etc/yum.repos.d/nginx.repo [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=0 enabled=1
三、安裝nginx
yum -y install nginx
四、測試nginx配置文件是否正確
nginx -t
打印如下:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
五、centos7.0+ nginx實現(xiàn)停止、啟動、重啟
systemctl stop nginx.service systemctl start nginx.service systemctl restart nginx.service systemctl status nginx.service
開機自啟:
systemctl enable nginx.service
取消開機自啟:
systemctl disable nginx.service
六、nginx.conf配置示例
我的配置:
user nginx; worker_processes 4; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; #設定負載均衡的服務器列表 upstream pay_server { ip_hash; server 10.74.248.01:8088 max_fails=2 fail_timeout=2; server 10.74.248.02:8088 max_fails=2 fail_timeout=2; } upstream print_server { ip_hash; server 10.74.248.03:2001 max_fails=2 fail_timeout=2; server 10.74.248.04:2001 max_fails=2 fail_timeout=2; } upstream accss_door_server { ip_hash; server 10.74.248.05:2002 max_fails=2 fail_timeout=2; server 10.74.248.06:2002 max_fails=2 fail_timeout=2; } server { listen 80; server_name wab.kupu.ccoop.com.cn; location /invengo { proxy_pass http://pay_server; index index.jsp index.html index.htm; } location /invengo/epc { proxy_pass http://print_server; index index.jsp index.html index.htm; } location /invengo/print { proxy_pass http://print_server; index index.jsp index.html index.htm; } location /checkout { proxy_pass http://accss_door_server; index index.jsp index.html index.htm; } location /asset { proxy_pass http://accss_door_server; index index.jsp index.html index.htm; } }
常用的nginx.conf配置:
user www www; worker_processes 2; error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; pid logs/nginx.pid; events { use epoll; worker_connections 2048; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; # tcp_nopush on; keepalive_timeout 65; # gzip壓縮功能設置 gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.0; gzip_comp_level 6; gzip_types text/html text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml; gzip_vary on; # http_proxy 設置 client_max_body_size 10m; client_body_buffer_size 128k; proxy_connect_timeout 75; proxy_send_timeout 75; proxy_read_timeout 75; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; proxy_temp_path /usr/local/nginx/proxy_temp 1 2; # 設定負載均衡后臺服務器列表 upstream backend { #ip_hash; server 192.168.10.100:8080 max_fails=2 fail_timeout=30s ; server 192.168.10.101:8080 max_fails=2 fail_timeout=30s ; } # 很重要的虛擬主機配置 server { listen 80; server_name itoatest.example.com; root /apps/oaapp; charset utf-8; access_log logs/host.access.log main; #對 / 所有做負載均衡+反向代理 location / { root /apps/oaapp; index index.jsp index.html index.htm; proxy_pass http://backend; proxy_redirect off; # 后端的web服務器可以通過x-forwarded-for獲取用戶真實ip proxy_set_header host $host; proxy_set_header x-real-ip $remote_addr; proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504; } #靜態(tài)文件,nginx自己處理,不去backend請求tomcat location ~* /download/ { root /apps/oa/fs; } location ~ .*\.(gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ { root /apps/oaapp; expires 7d; } location /nginx_status { stub_status on; access_log off; allow 192.168.10.0/24; deny all; } location ~ ^/(web-inf)/ { deny all; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } ## 其它虛擬主機,server 指令開始 }
“Linux環(huán)境下怎么安裝及使用Nginx”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關的知識可以關注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實用文章!
新聞名稱:Linux環(huán)境下怎么安裝及使用Nginx
文章來源:http://jinyejixie.com/article48/pdcjhp.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供電子商務、自適應網(wǎng)站、做網(wǎng)站、域名注冊、App設計、品牌網(wǎng)站設計
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)