Linux环境下安装Nginx及其使用

https://www.jb51.net/article/136161.htm

一、查看CentOS的版本

?


1

cat /etc/redhat-release

二、添加资源库

在 CentOS 系统上安装 Nginx ,得先去添加一个资源库:

?


1

2

3

4

5

6

vim /etc/yum.repos.d/nginx.repo

  [nginx]

  name=nginx repo

  baseurl=http://nginx.org/packages/centos/$releasever/$basearch/

  gpgcheck=0

  enabled=1

三、安装nginx

?


1

yum -y install nginx

四、测试nginx配置文件是否正确

?


1

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实现停止、启动、重启

?


1

2

3

4

systemctl stop nginx.service 

systemctl start nginx.service

systemctl restart nginx.service

systemctl status nginx.service

开机自启:

?


1

systemctl enable nginx.service

取消开机自启:

?


1

systemctl disable nginx.service

六、nginx.conf配置示例

我的配置:

?


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

user nginx;

worker_processes 4;

error_log /var/log/nginx/error.log warn;

pid    /var/run/nginx.pid;

events {

  worker_connections 1024;

}

http {

  include    /etc/nginx/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 /var/log/nginx/access.log main;

  sendfile    on;

  #tcp_nopush   on;

  keepalive_timeout 65;

  #gzip on;

  include /etc/nginx/conf.d/*.conf;

  #设定负载均衡的服务器列表

  upstream pay_server {

    ip_hash;

    server 10.74.248.01:8088 max_fails=2 fail_timeout=2;

    server 10.74.248.02:8088 max_fails=2 fail_timeout=2;

  }

  upstream print_server {

    ip_hash;

    server 10.74.248.03:2001 max_fails=2 fail_timeout=2;

    server 10.74.248.04:2001 max_fails=2 fail_timeout=2;

  }

  upstream accss_door_server {

    ip_hash;

    server 10.74.248.05:2002 max_fails=2 fail_timeout=2;

    server 10.74.248.06:2002 max_fails=2 fail_timeout=2;

  }

  

  server {

    listen 80;

    server_name wab.kupu.ccoop.com.cn;

    location /invengo {

         proxy_pass http://pay_server;

         index index.jsp index.html index.htm;

    }

    location /invengo/epc {

         proxy_pass http://print_server;

         index index.jsp index.html index.htm;

    }

    location /invengo/print {

         proxy_pass http://print_server;

         index index.jsp index.html index.htm;

    }

    location /checkout {

         proxy_pass http://accss_door_server;

         index index.jsp index.html index.htm;

    }

    location /asset {

         proxy_pass http://accss_door_server;

         index index.jsp index.html index.htm;

    }

  }

常用的nginx.conf配置:

?


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

user www www;

worker_processes 2;

error_log logs/error.log;

#error_log logs/error.log notice;

#error_log logs/error.log info;

pid    logs/nginx.pid;

events {

  use epoll;

  worker_connections 2048;

}

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 65;

 # gzip压缩功能设置

  gzip on;

  gzip_min_length 1k;

  gzip_buffers  4 16k;

  gzip_http_version 1.0;

  gzip_comp_level 6;

  gzip_types text/html text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml;

  gzip_vary on;

 

 # http_proxy 设置

  client_max_body_size  10m;

  client_body_buffer_size  128k;

  proxy_connect_timeout  75;

  proxy_send_timeout  75;

  proxy_read_timeout  75;

  proxy_buffer_size  4k;

  proxy_buffers  4 32k;

  proxy_busy_buffers_size  64k;

  proxy_temp_file_write_size 64k;

  proxy_temp_path  /usr/local/nginx/proxy_temp 1 2;

 # 设定负载均衡后台服务器列表

  upstream backend {

       #ip_hash;

       server  192.168.10.100:8080 max_fails=2 fail_timeout=30s ;

       server  192.168.10.101:8080 max_fails=2 fail_timeout=30s ;

  }

 # 很重要的虚拟主机配置

  server {

    listen    80;

    server_name itoatest.example.com;

    root  /apps/oaapp;

    charset utf-8;

    access_log logs/host.access.log main;

    #对 / 所有做负载均衡+反向代理

    location / {

      root  /apps/oaapp;

      index index.jsp index.html index.htm;

      proxy_pass    http://backend;

      proxy_redirect off;

      # 后端的Web服务器可以通过X-Forwarded-For获取用户真实IP

      proxy_set_header Host $host;

      proxy_set_header X-Real-IP $remote_addr;

      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

      proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;

      

    }

    #静态文件,nginx自己处理,不去backend请求tomcat

    location ~* /download/ {

      root /apps/oa/fs;

      

    }

    location ~ .*\.(gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ 

    

      root /apps/oaapp

      expires   7d;

    }

    location /nginx_status {

      stub_status on;

      access_log off;

      allow 192.168.10.0/24;

      deny all;

    }

    location ~ ^/(WEB-INF)/ { 

      deny all; 

    }

    #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;

    }

  }

 ## 其它虚拟主机,server 指令开始

}

原文地址:https://www.cnblogs.com/souphm/p/11107977.html

时间: 2024-08-30 14:43:58

Linux环境下安装Nginx及其使用的相关文章

linux环境下安装nginx步骤

开始前,请确认gcc g++开发类库是否装好,默认已经安装. ububtu平台编译环境可以使用以下指令 apt-get install build-essential apt-get install libtool centos平台编译环境使用如下指令 安装make: yum -y install gcc automake autoconf libtool make 安装g++: yum install gcc gcc-c++ 下面正式开始: 一.选定安装文件目录 可以选择任何目录,本文选择  

linux环境下安装nginx步骤(不错)

开始前,请确认gcc g++开发类库是否装好,默认已经安装. ububtu平台编译环境可以使用以下指令 apt-get install build-essential apt-get install libtool centos平台编译环境使用如下指令 安装make: yum -y install gcc automake autoconf libtool make 安装g++: yum install gcc gcc-c++ 下面正式开始: 一.选定安装文件目录 可以选择任何目录,本文选择  

Linux环境下安装Tigase XMPP Server

Tigase是一种XMPP服务器,可以作为采用XMPP协议的各种IM(Instant Messeging)工具(如Pandion.Spark等)的服务器. 在Linux环境下安装Tigase的步骤如下: (1)下载安装文件 到https://projects.tigase.org/projects/tigase-server/files下载安装文件,我下载的是tigase-server-5.2.0-b3447-dist.tar.gz. (2)解压缩 创建一个文件夹,将tigase-server-

windows下以及Linux环境下安装activeMQ

先去下载ActiveMQ,下载网址http://activemq.apache.org/activemq-5150-release.html(这里是5.15.0版本,目前是最新的) 1.windows环境下安装ActiveMQ 直接解压即可,根据你的操作系统,如果是64位的 运行D:\apache-activemq-5.14.5\bin\win64下的activemq.bat 或 运行D:\apache-activemq-5.14.5\bin\win64下的InstallService.bat

linux环境下安装qt过程

linux(虚拟机fedora9)环境下安装qt的过程主要是按照下面几网页上的教程完成的. http://mobile.51cto.com/symbian-272869.htm http://www.cnblogs.com/emouse/archive/2013/01/28/2880142.html http://wenku.baidu.com/link?url=7ipijK8ujQqvEkV4aJVD8L2CZqMEaejNJhoIS6hY8dCI0VTRDzRsqpNKyahl9DarynH

Linux环境下安装Nodejs

记录下 Linux 环境下 安装 Nodejs 系统安装环境:  Centos 6.5  x86_64 nodejs 版本:node-v0.10.26.tar.gz 软件安装目录: /pro_in 开始安装: 安装 编译工具  yum -y install gcc* cd  /pro_in   目录中: # tar zxvf node-v0.10.26.tar.gz   --解压 cd  /pro_in/node-v0.10.26   目录中: [[email protected] node-v

linux/centos下安装nginx(rpm安装和源码安装)详细步骤

Centos下安装nginx rpm包                                                                                                                            www.169it.com 1 在nginx官方网站下载一个rpm包,下载地址是:http://nginx.org/en/download.html wget http://nginx.org/packages/c

在linux环境下安装redis并且搭建自己的redis集群

此文档主要介绍在linux环境下安装redis并且搭建自己的redis集群 搭建环境: ubuntun 16.04 + redis-3.0.6 本文章分为三个部分:redis安装.搭建redis集群 一.本机安装redis: 1.下载redis: wget http://download.redis.io/releases/redis-3.0.6.tar.gz 2.redis安装解压.编译与安装:安装路径在root用户下的:~/softwares文件下 解压:先将安装包放到~/softwares

Linux环境下安装单实例MySQL 5.7

一.安装环境 1.操作系统版本:CentOS 7.5 2.MySQL版本:5.7.22(社区版) 3.MySQL安装包:mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz 二.安装步骤 1.检查系统中是否安装了其他版本的MySQL(root用户) 首先检查系统中是否安装了其他版本的MySQL,使用以下命令进行检查: yum list installed | grep mysql yum list installed | grep mariadb MariaDB数