yum list | grep nginx
出現相似下面的內容,說明yum源是存在的。php
安裝命令html
yum install nginx
查看版本nginx
nginx -v
配置目錄tc/nginx網絡
#運行用戶,默認便是nginx,能夠不進行設置 user nginx; #Nginx進程,通常設置爲和CPU核數同樣 worker_processes 1; #錯誤日誌存放目錄 error_log /var/log/nginx/error.log warn; #進程pid存放位置 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; #nginx訪問日誌存放位置 sendfile on; #開啓高效傳輸模式 #tcp_nopush on; #減小網絡報文段的數量 keepalive_timeout 65; #保持鏈接的時間,也叫超時時間 #gzip on; #開啓gzip壓縮 include /etc/nginx/conf.d/*.conf; #包含的子配置項位置和文件
server { listen 80; #配置監聽端口 server_name localhost; //配置域名 #charset koi8-r; #access_log /var/log/nginx/host.access.log main; location / { root /usr/share/nginx/html; #服務默認啓動目錄 index index.html index.htm; #默認訪問文件 } #error_page 404 /404.html; # 配置404頁面 # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; #錯誤狀態碼的顯示頁面,配置後須要重啓 location = /50x.html { root /usr/share/nginx/html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} }
ps aux | grep nginx
有這三條記錄,說明咱們Nginx被正常開啓了併發
沒有開啓app
nginx
啓動成功
啓動失敗,要先殺死nginx,再啓動tcp
killall nginx
在從新編寫或者修改Nginx的配置文件後,都須要做一下從新載入,這時候能夠用Nginx給的命令spa
nginx -s reload
在默認狀況下,Nginx啓動後會監聽80端口,從而提供HTTP訪問,若是80端口已經被佔用則會啓動失敗。我麼能夠使用netstat -tlnp命令查看端口號的佔用狀況。日誌
netstat -tlnp