CentOS下yum安装 Nginx

安装Nginx

# 查看相关信息

yum info nginx

yum info httpd

# 移除 httpd,也就是 Apache
yum remove httpd -y

#  安装 nginx
yum install nginx -y

#设置 nginx 自启动
chkconfig nginx on

# 查看服务自启动情况
chkconfig

# 启动nginx服务
service nginx start

#  查看端口监听状态
netstat -ntl

# 此时你可以访问试试了
# 例如: http://192.168.1.111:8080 等

# 如果访问不了,请 ping 一下试试
# 或者查看 iptables 防火墙状态
service iptables status

# 关闭防火墙,简单粗暴的
service iptables stop

如果你没有权限执行这些操作,你可能需要使用 sudo 权限

配置Nginx反向代理

/etc/nginx/nginx.conf

user              nginx;
worker_processes  1;

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

pid        /var/run/nginx.pid;

events {
    use epoll;
    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  0;
    keepalive_timeout  65;

    gzip  on;

    # Load config files from the /etc/nginx/conf.d directory
    # The default server is in conf.d/default.conf
    include /etc/nginx/conf.d/*.conf;

    include     upstream.conf;
    include     cncounter.com.conf; 

}

做负载的配置: /etc/nginx/upstream.conf

upstream www.cncounter.com {
    server 127.0.0.1:8080;
}

站点配置文件: /etc/nginx/cncounter.com.conf

server
{
    listen         80;
    server_name    www.cncounter.com;
    index index.jsp;
    root    /usr/local/cncounter_webapp/cncounter/;
    location ~ ^/NginxStatus/ {
    stub_status on;
    access_log off;
    }

    location / {
         root    /usr/local/cncounter_webapp/cncounter/;
         proxy_redirect off ;
         proxy_set_header Host $host;
         proxy_set_header X-Real-IP $remote_addr;
         proxy_set_header REMOTE-HOST $remote_addr;
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         client_max_body_size 50m;
         client_body_buffer_size 256k;
         proxy_connect_timeout 30;
         proxy_send_timeout 30;
         proxy_read_timeout 60;
         proxy_buffer_size 256k;
         proxy_buffers 4 256k;
         proxy_busy_buffers_size 256k;
         proxy_temp_file_write_size 256k;
         proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
         proxy_max_temp_file_size 128m;
         proxy_pass    http://www.cncounter.com;
    }
}

重启服务

service nginx stop

service nginx start

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-11-29 00:19:55

CentOS下yum安装 Nginx的相关文章

centos 下yum 安装nginx

centos 下yum 安装nginx 1. 直接yum install nginx不行,要先处理下源: rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm 2. 查看源: yum info nginx 这时会提示有可安装的软件包 nginx | 2.9 kB 00:00nginx/primary_db | 15 kB 00:00可安装的软件包Nam

centos下yum安装nginx

在/etc/yum.repos.d/目录下创建一个源配置文件nginx.repo cd   /etc/yum.repos.d/ vim  nginx.repo 填写如下内容: [nginx] name=nginx   repo baseurl=http://nginx.org/packages/centos/6/$basearch/ gpgcheck=0 enabled=1 保存. yum   install  nginx      ---安装nginx service    nginx   s

centos下yum安装lamp和lnmp轻松搞定

centos下yum安装lamp和lnmp轻松搞定,到底多轻松你看就知道了,妈妈再也不担心不会装lamp了. 很辛苦整理的安装方法,会持续更新下去.凡无法安装的在评论里贴出问题来,会尽快解决.共同维护一个可用yum可用更新. 软件列表:php5.4 apache2.2 mysql5.5 nginx1.8 centos6.x rpm -Uvh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ng

Centos下Yum安装PHP5.5,5.6,7.0

Centos下Yum安装PHP5.5,5.6,7.0 默认的版本太低了,手动安装有一些麻烦,想采用Yum安装的可以使用下面的方案: 1.检查当前安装的PHP包 yum list installed | grep php 如果有安装的PHP包,先删除他们 yum remove php.x86_64 php-cli.x86_64 php-common.x86_64 php-gd.x86_64 php-ldap.x86_64 php-mbstring.x86_64 php-mcrypt.x86_64 

centos下yum安装mysql5.6后,无法启动 MySQL Daemon failed to start

如果是全新安装应该就不会出现这个问题,升级安装的话,要运行 mysql_upgrade ,但是启动MYSQL就报错MySQL Daemon failed to start 如此就没办法运行mysql_upgrade升级MYSQL表了 因为是全新安装的数据库服务器就不管老数据了,直接把老的MYSQL数据库文件夹删除了,然后 运行 mysql_install_db 单独执行下命令,初始化mysql,test等数据库 初始化所有数据库以后,依然是无法启动,检查了MYSQL的日志发现没有权限,因为是RO

centos下yum安装lamp

CentOS下yum安装LAMP   1. 用yum安装Apache,Mysql,PHP. 1.1安装Apache yum install httpd httpd-devel 安装完成后,用/etc/init.d/httpd start 启动apache 设为开机启动:chkconfig httpd on 1.2 安装mysql 1.2.1 yum install mysql mysql-server mysql-devel 同样,完成后,用/etc/init.d/mysqld start 启动

centos直接yum安装nginx

Ubuntu下安装nginx,直接apt-get install nginx就行了,很方便. 但是今天装了CentOS6.2,直接yum install nginx不行,要先处理下源,下面是安装完整流程,也十分简单: 1.CentOS 6,先执行:rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm2,查看yum的nginx信息 []# yum inf

CentOS下yum安装FFmpeg

一.yum安装FFmpeg 1.    最偷懒的方式就是yum安装了,自动解决依赖.不过CentOS系统默认无FFmpeg源,企业版 Linux 附加软件包EPEL源也不包含,需要手动添加yum源配置/etc/yum.repos.d/dag.repo:   [dag] name=Dag RPM Repository for Red Hat Enterprise Linux baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag

服务器 CentOS上yum安装Nginx服务

一.更改yum源为网易的源加快速度 vi /etc/yum.repos.d/CentOS-Base.repo 更改内容如下 # CentOS-Base.repo # # This file uses a new mirrorlist system developed by Lance Davis for CentOS. # The mirror system uses the connecting IP address of the client and the # update status