# 参考链接
- https://www.runoob.com/linux/nginx-install-setup.html
# 安装过程
# 安装依赖
| yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel |
# 安装 pcre
PCRE 作用是让 Nginx 支持 Rewrite 功能。
| cd /usr/local/src/ |
| wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz |
| tar zxvf pcre-8.35.tar.gz |
| |
| cd pcre-8.35 |
| |
| ./configure |
| |
| make && make install |
| |
| |
| pcre-config --version |
# 安装 nginx
| cd /usr/local/src/ |
| sudo -s wget http://nginx.org/download/nginx-1.8.0.tar.gz |
| tar zxvf nginx-1.8.0.tar.gz |
| cd nginx-1.8.0 |
| ./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35 |
| |
| make && make install |
| |
| |
| /usr/local/webserver/nginx/sbin/nginx -v |
# nginx 配置
# 设置环境变量
| vi /etc/profile |
| |
| export PATH="$PATH:/usr/local/webserver/nginx/sbin" |
| |
| source /etc/profile |
# 创建 Nginx 运行使用的用户 www
| /usr/sbin/groupadd www |
| /usr/sbin/useradd -g www www |
# 配置文件 (部分)
| cat /usr/local/webserver/nginx/conf/nginx.conf |
| |
| |
| http{ |
| |
| user www www; |
| worker_processes auto; |
| error_log /usr/local/webserver/nginx/logs/nginx_error.log crit; |
| pid /usr/local/webserver/nginx/nginx.pid; |
| |
| worker_rlimit_nofile 65535; |
| events |
| { |
| use epoll; |
| worker_connections 65535; |
| } |
| |
| |
| include vhosts/*.conf; |
| } |
vhost 配置,例:我的 php tp5 框架 常用配置
/usr/local/webserver/nginx/conf/vhost/app.conf
| server { |
| listen 80; |
| server_name _; |
| root /data/www/om/public; |
| index index.php index.html index.htm; |
| |
| gzip on; |
| gzip_min_length 1k; |
| gzip_buffers 4 16k; |
| gzip_http_version 1.1; |
| gzip_comp_level 9; |
| gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php application/javascript application/json; |
| gzip_disable "MSIE [1-6]\."; |
| gzip_vary on; |
| |
| location / { |
| |
| if (!-e $request_filename) { |
| rewrite ^(.*)$ /index.php?s=/$1 last; |
| break; |
| } |
| |
| |
| } |
| |
| location ~ /(.+\.php)(/.+)*$ { |
| |
| |
| |
| client_max_body_size 10m; |
| fastcgi_pass_header Authorization; |
| fastcgi_split_path_info ^(.+\.php)(/.+)$; |
| fastcgi_pass 127.0.0.1:9000; |
| fastcgi_index index.php; |
| include fastcgi_params; |
| fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; |
| |
| fastcgi_param PATH_INFO $fastcgi_path_info; |
| fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/../:/tmp/:/proc/"; |
| } |
| |
| location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ |
| { |
| |
| add_header Access-Control-Allow-Origin '*'; |
| add_header Access-Control-Allow-Headers X-Requested-With; |
| add_header Access-Control-Allow-Methods GET,POST,OPTIONS; |
| |
| expires 30d; |
| access_log off; |
| } |
| } |