1、下载nginx
安装rpm命令: rpm ivh nginx-release.rpm。(直接使用linux命令下载wget http://nginx.org/packages/rhel/6/noarch/RPMS/nginx-release-rhel-6-0.el6.ngx.noarch.rpm
2、设置nginx开机启动
chkconfig nginx on
3、开启nginx服务
方法一:service nginx start
方法二:/usr/local/nginx/sbin/nginx
其他方法:
重新加载
/usr/local/nginx/sbin/nginx -s reload
如果更改了配置文件建议使用这个方式重新启动
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf停止服务
/usr/local/nginx/sbin/nginx -s stop
4、之后就会在/etc目录下有个nginx目录文件
如果不知道安装在什么地方,也可以使用 find /-name nginx 进行查找
5、安装之后的nginx目录结构如下
6、config配置
#user nobody;
worker_processes 1;#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;#pid logs/nginx.pid;events {worker_connections 1024;
}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 0;keepalive_timeout 65;#gzip on;server{listen 80 proxy_protocol;listen [::]:80 proxy_protocol;listen 431 ssl proxy_protocol;listen [::]:443 ssl proxy_protocol;server_name test.51jiayouya.com;ssl_certificate /home/ssl/test.51jiayouya.com.pem;ssl_certificate_key /home/ssl/test.51jiayouya.com.key;ssl_session_cache shared:SSL:1m;ssl_session_timeout 50m;ssl_protocols TLSv1 TLSv1.1 TLSv1.2;ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;ssl_prefer_server_ciphers on;if ($scheme = http) {rewrite ^(.*)$ https://$host$1 permanent;}access_log off;add_header Access-Control-Allow-Origin *;add_header Access-Control-Allow-Methods *;add_header Access-Control-Allow-Headers *;location / {proxy_pass http://127.0.0.1:8088;# proxy_set_header Host $host;# proxy_set_header X-Real-IP $remote_addr;# proxy_set_header X-Forwarded-Proto $scheme;# proxy_set_header X-Forwarded-Port $server_port;# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;# proxy_set_header REMOTE-HOST $remote_addr;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Real-IP $proxy_protocol_addr;proxy_set_header X-Forwarded-For $http_x_forwarded_for;proxy_set_header X-Forwarded-For $proxy_protocol_addr;add_header X-Cache $upstream_cache_status;#主要websocket代理配置, $http_upgrade是指http协议头部Upgrade的值. proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";#Set Nginx Cache#add_header Cache-Control no-cache;#expires 12h;}}}