CentOS에서 yum을 사용하여 Nginx 설치

WBOY
풀어 주다: 2016-07-29 09:15:37
원래의
800명이 탐색했습니다.

Nginx 설치

<code># 查看相关信息

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
</code>
로그인 후 복사

이러한 작업을 수행할 권한이 없으면 sudo 권한을 사용해야 할 수도 있습니다.

Nginx 역방향 프록시 구성

/etc/nginx/nginx.conf

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

}
</code>
로그인 후 복사

로드 구성: /etc/nginx/upstream.conf

<code>upstream www.cncounter.com {
    server 127.0.0.1:8080;
}
</code>
로그인 후 복사

사이트 구성 파일: /etc/nginx/cncounter.com.conf

<code>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;
    }
}
</code>
로그인 후 복사

서비스 다시 시작

<code>service nginx stop

service nginx start
</code>
로그인 후 복사

저작권 안내: 이 글은 해당 블로거의 원본 글이므로 블로거의 허가 없이 복제할 수 없습니다.

위 내용은 관련 내용을 포함하여 CentOS에서의 Nginx 설치에 대해 소개하고 있으며, PHP 튜토리얼에 관심이 있는 친구들에게 도움이 되기를 바랍니다.

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!