安装、配置与优化
2019-11-10 17:59:38    63    0    0
junjie
#安装 安装nginx ``` yum -y install nginx ``` yum install nginx 时报错:No package nginx available. 先安装epel: ``` yum install epel-release ``` 查看 ``` ps -aux | grep nginx ``` 安装php ``` yum install -y php72w php72w-opcache php72w-xml php72w-mcrypt php72w-gd php72w-devel php72w-mysql php72w-intl php72w-mbstring yum -y install php php-mysql php-cgi php-mbstring php-gd php-fastcgi ``` 安装spawn-fcgi来运行php-cgi ``` yum install spawn-fcgi ``` 下载spawn-fcgi 的启动脚本 ``` wget http://bash.cyberciti.biz/dl/419.sh.zip ; unzip 419.sh.zip mv 419.sh /etc/init.d/php_cgi chmod +x /etc/init.d/php_cgi ``` 启动php_cgi ``` /etc/init.d/php_cgi start ``` 查看进程 ``` netstat -tulpn | grep :9000 ``` 若出现如下代表一切正常 ``` tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 4352/php-cgi ``` #设置 开机启动 ``` chkconfig nginx on ``` 跨域 ``` add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Headers X-Requested-With; add_header Access-Control-Allow-Methods GET,POST,OPTIONS; ``` 配置文件 ``` worker_processes 8; # nginx 进程数,建议按照cpu 数目来指定,一般为它的倍数 (如,2个四核的cpu计为8)。据实践表明,nginx的这个参数在一般情况下开4个或8个就可以了,再往上开的话优化不太大。 worker_rlimit_nofile 204800; 将此值增加到大于worker_processes * worker_connections的值。 应该是增加当前worker运行用户的最大文件打开数值。 events { use epoll; #使用epoll事件驱动,因为epoll的性能相比其他事件驱动要好很多 worker_connections 20480; #指单个工作进程可以允许同时建立外部连接的数量。一个工作进程建立一个连接后,进程将打开一个文件副本。所以这个数量还受操作系统设定的,进程最大可打开的文件数有关。 } server { listen 80 default; server_name _; rewrite ^(.*) www.jun-chi.com; #未绑定域名自动跳转 } server { listen 80; server_name jun-chi.com www.jun-chi.com; client_max_body_size 10M; #默认上传的文件大小限制 root /usr/local/www/huoli; location / { root /usr/local/www/huoli; index index.html index.htm index.php; autoindex off; #禁止访问目录 } location ~ \.php$ { root /usr/share/nginx/html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name; include fastcgi_params; } } ``` 配置文件二 ``` server { listen 80; listen [::]:80; server_name apidemo.test; root /var/www/apidemo/public; index index.php index.html index.htm; location / { try_files $uri $uri/ /index.php$is_args$args; } location ~ \.php$ { try_files $uri /index.php =404; fastcgi_pass php-upstream; fastcgi_index index.php; fastcgi_buffers 16 16k; fastcgi_buffer_size 32k; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #fixes timeouts fastcgi_read_timeout 600; include fastcgi_params; } location ~ /\.ht { deny all; } location /.well-known/acme-challenge/ { root /var/www/letsencrypt/; log_not_found off; } error_log /var/log/nginx/apidemo_error.log; access_log /var/log/nginx/apidemo_access.log; } ``` --- 来源: - 实战Nginx与PHP(FastCGI)的安装、配置与优化 https://www.cnblogs.com/lidabo/p/4212419.html - https://www.cnblogs.com/wawahaha/p/4654950.html

上一篇: ECS能力测试

下一篇: 事件

Table of content