Linux安裝Nginx(yum方式 推薦)
阿新 • • 發佈:2021-12-14
## 摘抄nginx官網文件
URL:http://nginx.org/en/linux_packages.html#stable
執行如下命令 建立nginx yum配置檔案
cd /etc/yum.repos.d/
touchnginx.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
chmod -R 755 nginx.repo
Replace “OS
” with “rhel
” or “centos
”, depending on the distribution used, and “OSRELEASE
” with “6
” or “7
”, for 6.x or 7.x versions, respectively.
執行如下命令進行yum安裝nginx
yum install nginx
檢視nginx版本
# 檢視nginx版本 nginx -v # 檢視編譯引數 nginx -V
nginx.conf配置
vi /etc/nginx/nginx.conf
user nginx; worker_processes auto; error_log/var/log/nginx/error.log notice; 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; proxy_connect_timeout 600s; proxy_send_timeout 600s; proxy_read_timeout 600s; send_timeout 600s; #access_log /var/log/nginx/access.log main; client_max_body_size 1024M; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 300; types_hash_max_size 2048; #gzip on; include /etc/nginx/conf.d/*.conf; }
其他配置 示例
vi /etc/nginx/conf.d/test.conf
server { listen 80; server_name localhost; location / { # add_header Cache-Control "no-cache, no-store"; # add_header Access-Control-Allow-Origin *; # add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS'; root /data/web; try_files $uri $uri/ /index.html; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location /api{ #proxy_pass http://localhost:8888; } }
測試nginx配置是否OK
執行 nginx -t
啟動nginx
cd /usr/sbin
./nginx
重新啟動nginx
nginx -s reload