一、查看yum的nginx信息[root@server ~]# yum info nginx
二、安装并启动nignx[root@server ~]# yum install nginx
[root@server ~]# service nginx start
如果安装完成以后80端口被占用了,即使怎么停止占用80端口的应用,甚至删除应用,nginx -t都会提示
nginx: [emerg] socket() [::]:80 failed (97: Address family not supported by
解决办法是修改配置文件:(# vim /etc/nginx/conf.d/default.conf)
listen 80 default_server;
listen [::]:80 default_server;
改成:
listen 80 default_server;
#listen [::]:80 default_server;
三、设置开机启动[root@server ~]# chkconfig nginx on
四、优化配置参考
nginx.conf:#user www-data;
#pid /var/run/nginx.pid;
worker_processes 1;
#worker_rlimit_nofile 100000;
events {
worker_connections 2048;
multi_accept on;
use epoll;
}
http {
server_tokens off;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
access_log off;
error_log /var/log/nginx/error.log crit;
keepalive_timeout 10;
client_header_timeout 10;
client_body_timeout 10;
reset_timedout_connection on;
send_timeout 10;
limit_conn_zone $binary_remote_addr zone=addr:5m;
limit_conn addr 100;
include /etc/nginx/mime.types;
default_type text/html;
charset UTF-8;
gzip on;
gzip_disable "msie6";
gzip_proxied any;
gzip_min_length 1000;
gzip_comp_level 6;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
open_file_cache max=100000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
此配置参考至:http://www.oschina.net/translate/nginx-setup
ziry.conf:server{
listen 80;
server_name www.ziry.me;
location / {
proxy_pass http://127.0.0.1:8080;
#Proxy Settings
proxy_redirect off;
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;
proxy_max_temp_file_size 0;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
}
更多关于配置详情请参考:
注意:本文归作者所有,未经作者允许,不得转载