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;
# }
#}
}