CentOS6.9安装nginx-1.17.9.tar.gz
一、安装
1、官网 http://nginx.org/en/download.html
2、安装依赖 yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
3、解压到指定文件夹 tar -zxvf nginx-1.17.9.tar.gz /home/
4、执行 ./configure
5、执行 make
6、安装 make install
7、启动 ./nginx
8、重启 ./nginx -s reload
9、查看启动状态 ps aux| grep nginx
10、浏览器访问:ip
二、配置域名转发
1、编辑主配置文件
cd /usr/local/nginx/conf/
vim nginx.conf
添加 include vhost/*.conf;
2、创建文件夹 mkdir vhost
3、域名转发
cd vhost/
vim www.xxx.net.conf
server {
listen 80;
autoindex on;
server_name www.xxx.net;
access_log /usr/local/nginx/logs/access.log combined;
index index.html index.htm index.jsp index.php;
if ( $query_string ~* ".*[\;'\<\>].*" ){
return 404;
}
location / {
proxy_pass http://xxx:8080;
add_header Access-Control-Allow-Origin *;
}
}
4、图片转发
server {
listen 80;
autoindex off;
server_name img.xxx.net;
access_log /usr/local/nginx/logs/access.log combined;
index index.html index.htm index.jsp index.php;
#error_page 404 /404.html;
if ( $query_string ~* ".*[\;'\<\>].*" ){
return 404;
}
location / {
root /home/ftpfile/img/;
add_header Access-Control-Allow-Origin *;
}
}
5、重启 ./nginx -s reload
6、访问一:域名访问www.xxx.net
访问二:img.xxx.net/image.jpg