nginx安裝
以centos7.4系統爲例
http://nginx.org/en/download.html下載安裝包(此處以nginx-1.12.2版本爲例)
[root@shitouji ~]# mkdir /usr/local/nginx
[root@shitouji ~]# groupadd nginx && useradd -g nginx nginx -s /bin/false
./configure --prefix=/usr/local/nginx/ --user=nginx --group=nginx --with-http_sub_module --with-http_ssl_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module
#./cnfigure --help 查看模塊,根據需要配置添加需要模塊
make && make install
命令簡化
echo 'export PATH=/usr/local/nginx/sbin:$PATH'>>/etc/profile
source /etc/profile
which nginx
cd /usr/local/nginx/conf 中,編輯nginx.conf文件,進行配置,注意端口號,默認是80
查看進程是否啓動及所監聽的端口
查看安裝後Nginx的默認配置
#user nobody; #啓用用戶
worker_processes 1; #worker進程數
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #錯誤日誌設置開啓和級別
#pid logs/nginx.pid; #存放pid號
events { #事件區塊
worker_connections 1024; #每個worker進程可以處理的連接數
}
http { #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 0;
keepalive_timeout 65; #超時時間
#gzip on;
server {
listen 8080;
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;
# 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 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}