這篇文章給大家分享的是有關nginx怎么安裝的內容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
0.下載
wget http://nginx.org/download/nginx-1.0.4.tar.gz
2.運行
/usr/local/nginx/sbin/nginx #注:nginx默認使用80端口,若是80端口被占用,修改/usr/local/nginx/conf/nginx.conf里的 server { listen 80;
3.測試
echo "test123" > /usr/local/nginx/html/index.html wget http://127.0.0.1
4.基本命令
/usr/local/nginx/sbin/nginx -h #幫助 /usr/local/nginx/sbin/nginx -v #顯示版本 /usr/local/nginx/sbin/nginx -V #顯示版本和配置信息 /usr/local/nginx/sbin/nginx -t #測試配置 /usr/local/nginx/sbin/nginx -q #測試配置時,只輸出錯誤信息 /usr/local/nginx/sbin/nginx -s stop #停止服務器 /usr/local/nginx/sbin/nginx -s reload #重新加載配置 /usr/local/nginx/sbin/nginx -s quit #不知道,估計和stop差不多 /usr/local/nginx/sbin/nginx -s reopen #不知道,估計和reload類似 /usr/local/nginx/sbin/nginx -p /nginx/path #默認為/usr/local/nginx(nginx安裝路徑),修改后影響log目錄和html目錄 /usr/local/nginx/sbin/nginx -c /configure/file/path #配置文件路徑,默認為conf/nginx.conf,有多個配置文件時很有用,用這個可以啟動多個不同的nginx監聽不同端口 /usr/local/nginx/sbin/nginx -g #沒用過
#user nobody; #nginx啟動使用的用戶,配置fastcgi時,需要改為有權限執行fastcgi的用戶 worker_processes 1; #nginx啟動的進程數,1個已經足夠了 #error_log logs/error.log; #nginx 錯誤日志 相對于/usr/local/nginx/ #error_log logs/error.log notice; #nginx 記錄警告日志 相對于/usr/local/nginx/ ,可改為 logs/notice.log #error_log logs/error.log info; #nginx 記錄信息日志 相對于/usr/local/nginx/ ,可改為 logs/info.log #pid logs/nginx.pid; #nginx進程文件,最好不要改 events { worker_connections 1024; #nginx最大連接數,最好小于系統的socket最大數和文件打開數 } http { include mime.types; #見同目錄mime.types,用于根據文件后綴產生http header 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 0; keepalive_timeout 65; #保持連接時間,單位:秒 #gzip on; server { listen 80; #監聽的端口 server_name localhost; #服務器名 #charset koi8-r; #默認字符集 #access_log logs/host.access.log main; #根據訪問域名生成對應的訪問日志 location / { root html; #根目錄,相對于安裝目錄 index index.html index.htm; #默認主頁 } #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; } # 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; #轉發到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; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443; # server_name localhost; # ssl on; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_timeout 5m; # ssl_protocols SSLv2 SSLv3 TLSv1; # ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} }
5.配置
配置文件在 安裝目錄/conf/nginx.conf
修改完后用 /usr/local/nginx/sbin/nginx -s reload重新加載
1.安裝
默認安裝到/usr/local/nginx
tar -zxvf nginx-1.0.4.tar.gz cd nginx-1.0.4 ./configure make;make install
感謝各位的閱讀!關于“nginx怎么安裝”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。