Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Installation and use of Nginx in Linux Environment

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

1. Check the version of CentOS

Cat / etc/redhat-release

Second, add a resource base

To install Nginx on a CentOS system, you must first add a repository:

Vim / etc/yum.repos.d/nginx.repo [nginx] name=nginx repo baseurl= http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=0 enabled=1

Third, install nginx

Yum-y install nginx

4. Test whether the nginx configuration file is correct

Nginx-t

Print as follows:

Nginx: the configuration file / etc/nginx/nginx.conf syntax is ok

Nginx: configuration file / etc/nginx/nginx.conf test is successful

5. CentOS7.0+ nginx can stop, start and restart.

Systemctl stop nginx.servicesystemctl start nginx.servicesystemctl restart nginx.servicesystemctl status nginx.service

Self-booting:

Systemctl enable nginx.service

Cancel Boot:

Systemctl disable nginx.service

VI. Nginx.conf configuration example

My configuration:

User nginx;worker_processes 4 errorists 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 # set the list of servers for cloud load balancer upstream pay_server {ip_hash; server 10.74.248.01 max_fails=2 fail_timeout=2; server 8088 max_fails=2 fail_timeout=2; server 10.74.248.02 max_fails=2 fail_timeout=2; server 8088 max_fails=2 fail_timeout=2;} upstream print_server {ip_hash; server 10.74.248.03 upstream print_server 2001 max_fails=2 fail_timeout=2; server 10.74.248.04 max_fails=2 fail_timeout=2; server 2001 max_fails=2 fail_timeout=2;} upstream accss_door_server {ip_hash Server 10.74.248.05 max_fails=2 fail_timeout=2; server 10.74.248.06 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;}}

Common nginx.conf configurations:

User www www;worker_processes 2 error 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 compression function sets 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 set 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 12; # set load balancer backend server list upstream backend {# ip_hash; server 192.168.10.100 usr/local/nginx/proxy_temp 8080 max_fails=2 fail_timeout=30s; server 192.168.10.101 usr/local/nginx/proxy_temp 8080 max_fails=2 fail_timeout=30s;} # very important virtual host configuration server {listen 80 Server_name itoatest.example.com; root / apps/oaapp; charset utf-8; access_log logs/host.access.log main; # pair / all do load balancing + reverse proxy location / {root / apps/oaapp; index index.jsp index.html index.htm; proxy_pass http://backend; proxy_redirect off # backend Web servers can obtain users' real 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 through X-Forwarded-For } # static files, processed by nginx itself, do not go to backend to request tomcat location ~ * / download/ {root / apps/oa/fs;} location ~. *\. (gif | jpg | jpeg | png | png | txt | js | css) ${root / apps/oaapp; expires 7d;} location / nginx_status {stub_status on; access_log off; allow 192.168.10.0x24 Deny all;} location ~ ^ / (WEB-INF) / {deny all;} # error_page 404 / 404.html; # redirect server error pages to the static page / 50x.html # error_page 500502503504 / 50x.hml; location = / 50x.html {root html;} # # other virtual hosts, server instruction starts}

The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report