centOS7安装nginx及nginx配置
gcc -v
yum -y install gcc
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
进入到:
usr/local/java
wget http://nginx.org/download/nginx-1.9.9.tar.gz
tar -zxvf nginx-1.9.9.tar.gz
cd /usr/local/java/nginx-1.9.9
./configure
make
注意:这里 “make” 在centos8的环境下会报错,出现如下两个错误不要慌,按照步骤解决就行:
make install
切换到/usr/local/nginx安装目录
配置nginx的配置文件nginx.conf文件,主要也就是端口
进入到/usr/local/nginx/sbin/
./nginx 启动
./nginx -s stop 停止
./nginx -s reload 重启
以上启停方式作废
正确的方式:
启动:/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
停止:/usr/local/nginx/sbin/nginx -s stop -c /usr/local/nginx/conf/nginx.conf
设置NGINX的浏览器跨域问题:
location /netconfig/ {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods ‘GET, POST, OPTIONS’;
add_header Access-Control-Allow-Headers ‘DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization’;
autoindex on;
alias /home/netconfig/backup/;
}