Nginx (engine x) 是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器。Nginx是由伊戈尔·赛索耶夫为俄罗斯访问量第二的Rambler.ru站点开发的。
中文官网地址:https://www.nginx.cn/doc/
1、yum 安装 或者下载安装包
yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && bash install.sh
1.1 也可以下下载安装包
http://nginx.org/en/download.html
上传到服务器位置:
/usr/local
2. 解压到nginx目录下
tar xf nginx-1.9.9.tar.gz
cd nginx-1.9.9
3. 运行
./configure --prefix=/usr/local/nginx
4. 编译
make
make install
5. 启动
cd ../nginx
./sbin/nginx
6. kill
netstat -ntlp | grep nginx
ps -ef | grep nginx
kill -9 10581 --- 端口号
1.修改配置文件
# 1. 首先修改nginx的配置文件 nginx/conf/nginx.conf
# 2. 将user nobady 改成 user root (原来得注释掉即可)
---- 这里得意思是 root权限访问文件 配置文件如下----
#user nobody;
user root;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
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; # 开启gzip
gzip_disable "msie6"; #IE6 不适用gzip
gzip_vary on; # 设置为on 会在Header里增加 ”Vary:Accept-Encodng“
gzip_proxied any:# 代理数据结果得压缩
gzip_comp_level 6; # gzip压缩比( 1-9 ),越小压缩效果越差,但是越大处理效果越慢,所以一般取中间值
gzip_buffers 18 8k; # 获取多少内存用于缓存压缩结果
gzip_http_version 1.1; # 识别http协议版本
gzip_min_length 1k; #设置允许压缩得页面最小字节数,超过1k得文件会被压缩
gzip_types application/javascipt text/css; # 对特定得MIME类型生效,js和css文件会被压缩
include /usr/local/nginx/vhosts/*;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
location /images/ {
root /ui/;
autoindex on;
}
#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;
# }
#}
}
3.nginx指向地址
上边已经有了,拿出来看明显一点。
location /images/ {
root /ui/;
autoindex on; # 开启浏览器功能
}
记得要重启服务。
IP地址/images/图片名称
效果如下: