linux 安装 nginx

nginx安装

参考资料

1 安装参考资料: https://www.cnblogs.com/kaid/p/7640723.html
2 ngix 官网:https://nginx.org/en/download.html
3 ssl 参考资料: https://www.cnblogs.com/saneri/p/5391821.html
4 配置详解:http://www.nginx.cn/76.html

安装包准备

1 nginx 官网下载 nginx稳定版本压缩包
2 服务器分目录下新建文件夹 /install/nginx
3 上传nginx压缩包 至文件夹	
4 解压
	命令: tar -zxvf 压缩包名称 -c 文件目录
		例:tar -zxvf nginx-1.10.1.tar.gz -c /opt

安装

1 安装编译依赖环境gcc环境
	命令:yum install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
	如果安装失败,清空缓存后重试
2 进入安装目录
	命令:cd /opt/nginxxxx
		例:cd /opt/nginx-1.12.2
3 在nginx中安装 ssl 模块
	命令: ./configure --prefix=/opt/nginx --with-http_ssl_module
4 在安装目录下编译安装
	命令: make
	命令: make install
5 配置nginx
	命令 vim /opt/nginx/conf/nginx.conf

开放端口

	如果防火墙开启则需要开放端口:
	添加开放端口命令   firewall-cmd --permanent --add-port=80/tcp
    使配置生效   firewall-cmd --reload

常用命令

1 重启命令:
	/opt/nginx/sbin/nginx -s reload
2 停止命令:
	/opt/nginx/sbin/nginx -s stop
3 查看nginx 进程
	ps aux|grep nginx
4 指定配置文件启动
	./opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf

验证

1 浏览器访问 服务器IP:80 访问成功

nginx.conf

 仅提供主要配置信息 
 upstream server-name  {
	server localhost:30000;
}

server {
    listen       4200;
    server_name  localhost 127.0.0.1 ;
location ~* /server_name {
	if ($request_method = 'OPTIONS') {
		add_header 'Access-Control-Allow-Origin' '*';
		add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
		add_header 'Access-Control-Allow-Credentials' 'false';
		add_header 'Access-Control-Allow-Headers' '*';
		add_header 'Access-Control-Expose-Headers' '*';
		add_header 'Content-Length' 0;
		return 204;
	}
	proxy_pass http://server-name;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值