Rumah > Artikel > Operasi dan penyelenggaraan > Bagaimana untuk memasang dan menggunakan Nginx dalam persekitaran Linux
1. Semak versi centos
cat /etc/redhat-release
2. Tambah pustaka sumber
Untuk memasang nginx pada sistem centos, anda mesti mula-mula tambahkan perpustakaan sumber:
vim /etc/yum.repos.d/nginx.repo [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=0 enabled=1
3 Pasang nginx
yum -y install nginx
4 fail konfigurasi nginx ialah
nginx -t
yang betul mencetak seperti berikut:
nginx: sintaks konfigurasi /etc/nginx/nginx.conf ok
nginx : fail konfigurasi /etc/nginx /nginx.conf ujian berjaya
5. Centos7.0+ nginx menyedari berhenti, memulakan dan memulakan semula
rreeeAuto mula semasa but:
systemctl stop nginx.service systemctl start nginx.service systemctl restart nginx.service systemctl status nginx.service
Batalkan automula semasa but:
systemctl enable nginx.service
6. contoh konfigurasi nginx.conf
Konfigurasi saya:
systemctl disable nginx.service
Konfigurasi nginx.conf yang biasa digunakan:
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; } }
Atas ialah kandungan terperinci Bagaimana untuk memasang dan menggunakan Nginx dalam persekitaran Linux. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!