安装nginx
yum -y install nginx
测试是否安装正确:
nginx -t
打印如下:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
CentOS7.0+ nginx实现停止、启动、重启
systemctl stop nginx.service;
systemctl start nginx.service;
systemctl restart nginx.service;
systemctl status nginx.service;
开机自启:
systemctl enable nginx.service
取消开机自启:
systemctl disable nginx.service

nginx配置的修改:
修改nginx.conf(位置在/etc/nginx/)文件,可将配置文件放在一个文件夹中,让nginx自己去读取自定义的配置文件,修改结果如下
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/ user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid; # Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf; events {
worker_connections 1024;
} http {
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 /var/log/nginx/access.log main; sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048; include /etc/nginx/mime.types;
default_type application/octet-stream; # Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
}
include /etc/nginx/conf.d/*.conf;这一句的意思是从/etc/nginx/conf.d/文件夹中搜索所有*.conf的配置文件填充进配置中,例如我发布了一个网站,端口号是5000,如果不进行nginx映射,只能在linux的内网中进行访问,
无法在外网进行访问

例如我在/etc/nginx/conf.d/中添加了myblog.conf,如下面,重启nginx后,80端口的http请求都会转向到内部的5000端口,这样自己的网站就可以访问了

server {
listen 80;
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_ipgrade;
}
}

linux nginx搭建与使用的更多相关文章

  1. linux下搭建Nginx

    Linux上搭建nginx,及简单配置  在上家公司都是运维安装nginx,到新公司后代码开发完成部署测试服务器要求自己装nginx,研究了好久安装好之后,到正式上线还要自己安装,索性把安装步骤自己记 ...

  2. Linux+.NetCore+Nginx搭建集群

    本篇和大家分享的是Linux+NetCore+Nginx搭建负载集群,对于netcore2.0发布后,我一直在看官网的文档并学习,关注有哪些新增的东西,我,一个从1.0到2.0的跟随者这里只总结一句话 ...

  3. 阿里云服务器部署php的laravel项目,在阿里云买ECS 搭建 Linux+Nginx+Mysql+PHP环境的

    在阿里云买ECS的时候选择自己习惯的镜像系统,我一般都是使用Linux Ubuntu,所以,以下的配置都是在Ubuntu 14.04稳定支持版的环境中搭建Linux+Nginx+Mysql+PHP环境 ...

  4. 使用Nginx在windows和linux上搭建集群

    Nginx Nginx (engine x) 是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器 特点:反向代理 负载均衡 动静分离… 反向代理(Reverse Pro ...

  5. 转:Linux下使用Nginx搭建简单图片服务器

    最近经常有人问图片上传怎么做,有哪些方案做比较好,也看到过有关于上传图片的做法,但是都不是最好的,今天再这里简单讲一下Nginx实现上传图片以及图片服务器的大致理念. 如果是个人项目或者企业小项目,仅 ...

  6. Linux yum的配置 , python环境管理, nginx搭建简单学习

    Linux yum的配置 , python环境管理, nginx搭建简单学习 一丶配置yum的数据仓库 ### yum 工具, 方便,自行解决软件之间的依赖关系. # 配置yum源仓库 (可以使用,清 ...

  7. nginx 搭建图片服务器(windows 下,linux 下原理应该一样)

    作者的心声:很多知道的.用过的东西,不写下来,下次还要百度查询,浪费时间和精力,故本次写下学习笔记,方便下次查阅. 题外话:如有读者通过我这篇博客解决了工作上的难题,可以给个评论,让我一起分享你的喜悦 ...

  8. LNMP(Linux+Nginx+Mysql+PHP---源码)环境搭建

    LNMP(Linux+Nginx+Mysql+PHP(Perl)) Linux:[root@dep5 mysql]# cat /etc/issueRed Hat Enterprise Linux Se ...

  9. linux nginx 配置ssl证书访问

    http://www.linuxidc.com/Linux/2013-08/88271.htm 一.什么是 SSL 证书,什么是 HTTPSSSL 证书是一种数字证书,它使用 Secure Socke ...

随机推荐

  1. 结合 Vuex 和 Pinia 做一个适合自己的状态管理 nf-state

    一开始学习了一下 Vuex,感觉比较冗余,就自己做了一个轻量级的状态管理. 后来又学习了 Pinia,于是参考 Pinia 改进了一下自己的状态管理. 结合 Vuex 和 Pinia, 保留需要的功能 ...

  2. 【数据库】MySQL如何删除索引

    1.查看表上的索引 -- 查看table_name表上的索引 show index from table_name ; 2.删除表上的索引 删除索引可以使用ALTER TABLE或DROP INDEX ...

  3. VS.NET启动显示ID为XXXX的进程当前未运行

    解决办法:在启动项目根目录下用文本编辑器打开Web项目下的{X}.csproj文件,然后查找 <WebProjectProperties>,将这一对标签之间的内容全部删除,然后再打开项目就 ...

  4. 590. N-ary Tree Postorder Traversal - LeetCode

    Question 590. N-ary Tree Postorder Traversal Solution 题目大意:后序遍历一个树 思路: 1)递归 2)迭代 Java实现(递归): public ...

  5. ElasticSearch7.3学习(二十八)----聚合实战之电视案例

    一.电视案例 1.1 数据准备 创建索引及映射 建立价格.颜色.品牌.售卖日期 字段 PUT /tvs PUT /tvs/_mapping { "properties": { &q ...

  6. [2-SAT]编码

    题意:给n个01字符串,每个最多包含1个'?',能否构造出满足两两不存在一个是另一个前缀的方案. 思路: 2-SAT+trie树优化建图 把每个字符串拆成i,i+n,如果不存在'?',就硬搞出两种情况 ...

  7. springcloud 断路器

    https://www.jb51.net/article/138572.htm 参考资料: http://www.cnblogs.com/ulysses-you/p/7281662.html http ...

  8. mysql复制表的两种方式

    mysql复制表的两种方式. 第一.只复制表结构到新表 create table 新表 select * from 旧表 where 1=2 或者 create table 新表 like 旧表 第二 ...

  9. 前端ES6 特性兼容查询

    ES6 http://kangax.github.io/compat-table/es6/ ES5 http://kangax.github.io/compat-table/es5/ ES 2016+ ...

  10. 【Spring】AOP实现原理(三):创建代理

    AbstractAutoProxyCreator 在AbstractAutoProxyCreator的wrapIfNecessary方法中,调用getAdvicesAndAdvisorsForBean ...